Convert word to bool to word

I receive a variable as a word, but in that word information is coded as bits.
So after I receive the variable, I need to split up the word into bits, then do stuff, and then reassemble the bits into that word again to send it off.

Example:
I receive 22553
which is 01011000 00011001
I now need to address the individual bits and work with them
result might be: 00010000 01011100
so I send back: 4188

how do I do that in node red??

do it in a function node, where you can write standard javascript.

Has to convert a string to binary in javascript is easy to google for as is binary to dec

the modifications are not done in the function but throughout the flows.
So I need the bits addressable throughout node red, not just in a function

The convert it with a function and pass the result along your flow

This may help
https://www.w3schools.com/js/js_bitwise.asp

You could, in a Function node, split it into an array of values or an object with named properties, one for each bit, then pass that on.

1 Like

thanks Colin,
Yes, I think object with named properties is what I want...

that means
msg.bits.number1
.
.
.
msg.bits.number16

right?

how do I get those 16 bits back into on dec value at the end of the flow?

A bit of javascript

1 Like