Convert word to bool to word

#1

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??

0 Likes

#2

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

0 Likes

#3

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

0 Likes

#4

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

0 Likes

#5

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

0 Likes

#6

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

#7

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?

0 Likes

#8

A bit of javascript

1 Like