# Combine and convert into an integer value

**URL:** <https://discourse.nodered.org/t/combine-and-convert-into-an-integer-value/66434>\
**Category:** General\
**Created:** [15 August 2022 07:59 UTC](https://discourse.nodered.org/t/combine-and-convert-into-an-integer-value/66434 "2022-08-15T07:59:27Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ganesh](https://avatars.discourse-cdn.com/v4/letter/g/f19dbf/32.png) [@Ganesh](https://discourse.nodered.org/u/Ganesh)\
**Post date:** [15 August 2022 07:59 UTC](https://discourse.nodered.org/t/combine-and-convert-into-an-integer-value/66434/1 "2022-08-15T07:59:27Z")

</div>

Hi  
I have multi - level sliders each representing an sensor giving 1 or 0 bit based on input which can be seen in debug window , these induvial values i have to combine and convert into an integer value

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/d/4d634ac0a4a9dbc24892b1b245074d79058a4ecb.png)

[Moderator Note: Moved to new thread]

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [15 August 2022 08:41 UTC](https://discourse.nodered.org/t/combine-and-convert-into-an-integer-value/66434/2 "2022-08-15T08:41:03Z")

</div>

What is the order of the bits? Looking at the debug is it top to bottom, bottom to top?  
Do you need to wait for all bits to arrive before converting?  
What have you tried so far?

In your function node you could test each variable and add to a total, the value that that bit position would equate to i.e.;

```auto
let my_int = 0
if (bit0 = 1) my-int = my_int +1
if (bit1 = 1) my-int = my_int +2
if (bit2 = 1) my-int = my_int +4
etc

```

---

<div class="post-metadata">

**Author:** ![Ganesh](https://avatars.discourse-cdn.com/v4/letter/g/f19dbf/32.png) [@Ganesh](https://discourse.nodered.org/u/Ganesh)\
**Post date:** [15 August 2022 10:07 UTC](https://discourse.nodered.org/t/combine-and-convert-into-an-integer-value/66434/3 "2022-08-15T10:07:36Z")

</div>

Hi  
the order of the bits is top to bottom looking at debug  
I need all the bits before converting  
i have tried using join node to combine it then convert it into integer, but not all the bits are going to come at once (since these are control inputs)  
so i have to store these values somewhere before using it .  
Need Help in doing that  
Thanks

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [15 August 2022 14:30 UTC](https://discourse.nodered.org/t/combine-and-convert-into-an-integer-value/66434/4 "2022-08-15T14:30:01Z")

</div>

Set a unique topic for every msg then use the `join` node and set it 'manual' and set the 'After a number of message parts' to the number of messages you need. Then uncheck the 'and every subsequent message`.

Now once all the messages come thru, you will get one msg fom the join that you can use to convert the bits into an integer.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [15 August 2022 14:45 UTC](https://discourse.nodered.org/t/combine-and-convert-into-an-integer-value/66434/5 "2022-08-15T14:45:13Z")

</div>

Do you get messages for all the bits every time or do you only get the ones that change? If you only get the ones that change then how do you know when you should do the conversion?

---

<div class="post-metadata">

**Author:** ![Ganesh](https://avatars.discourse-cdn.com/v4/letter/g/f19dbf/32.png) [@Ganesh](https://discourse.nodered.org/u/Ganesh)\
**Post date:** [17 August 2022 10:00 UTC](https://discourse.nodered.org/t/combine-and-convert-into-an-integer-value/66434/6 "2022-08-17T10:00:42Z")

</div>

In above image you can see PMP and HTP nodes which are sliders used as control the on(1) and off(0) status of pumps , EX = I will turn off pmp902 and rest as on.  
slider will send out 0 bit or 1 bit as output , so the output from sliders will be 1,0,1,1 which I have to combine and convert into integer  
I only get the ones that changes  
when I change the status to on or off that's when I will do the conversion

---

<div class="post-metadata">

**Author:** ![Ganesh](https://avatars.discourse-cdn.com/v4/letter/g/f19dbf/32.png) [@Ganesh](https://discourse.nodered.org/u/Ganesh)\
**Post date:** [17 August 2022 10:14 UTC](https://discourse.nodered.org/t/combine-and-convert-into-an-integer-value/66434/7 "2022-08-17T10:14:29Z")

</div>

Hi  
Most of the time I will be changing only 1 or 2 pumps on or off so I wont be receiving all the bits , and I have to do conversion every time I change the status , So cant use Join node

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [17 August 2022 10:22 UTC](https://discourse.nodered.org/t/combine-and-convert-into-an-integer-value/66434/8 "2022-08-17T10:22:16Z")

</div>

> [@Ganesh](#):
>
> So cant use Join node

Yes you can, set it to send After 1 message part and select And Every Subsequent. Then you will get an output for every input. Make sure the code allows for the fact that on startup only some of the inputs will have values, or if all the inputs will automatically appear on startup then you can set it to not send anything until the right number of values has been seen, and then after every subsequent.

---

<div class="post-metadata">

**Author:** ![Ganesh](https://avatars.discourse-cdn.com/v4/letter/g/f19dbf/32.png) [@Ganesh](https://discourse.nodered.org/u/Ganesh)\
**Post date:** [23 August 2022 07:28 UTC](https://discourse.nodered.org/t/combine-and-convert-into-an-integer-value/66434/9 "2022-08-23T07:28:48Z")

</div>

Hi  
Can you Share an example flow it will be helpful  
Thanks

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [23 August 2022 07:59 UTC](https://discourse.nodered.org/t/combine-and-convert-into-an-integer-value/66434/10 "2022-08-23T07:59:11Z")

</div>

I think it would be better for you to share what you have tried, following the suggestions given. Export just enough that we can test it, preferably just using standard nodes.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [6 September 2022 07:59 UTC](https://discourse.nodered.org/t/combine-and-convert-into-an-integer-value/66434/11 "2022-09-06T07:59:20Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
