Combine and convert into an integer value

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

[Moderator Note: Moved to new thread]

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.;

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

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

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.

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?

1 Like

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

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

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.

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

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.

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