# Convert word to bool to word

**URL:** <https://discourse.nodered.org/t/convert-word-to-bool-to-word/5852>\
**Category:** General\
**Created:** [16 December 2018 15:46 UTC](https://discourse.nodered.org/t/convert-word-to-bool-to-word/5852 "2018-12-16T15:46:47Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![martinschki](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/martinschki/32/737_2.png) [@martinschki](https://discourse.nodered.org/u/martinschki)\
**Post date:** [16 December 2018 15:46 UTC](https://discourse.nodered.org/t/convert-word-to-bool-to-word/5852/1 "2018-12-16T15:46:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [16 December 2018 16:00 UTC](https://discourse.nodered.org/t/convert-word-to-bool-to-word/5852/2 "2018-12-16T16:00:17Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![martinschki](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/martinschki/32/737_2.png) [@martinschki](https://discourse.nodered.org/u/martinschki)\
**Post date:** [16 December 2018 16:04 UTC](https://discourse.nodered.org/t/convert-word-to-bool-to-word/5852/3 "2018-12-16T16:04:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [16 December 2018 16:07 UTC](https://discourse.nodered.org/t/convert-word-to-bool-to-word/5852/4 "2018-12-16T16:07:29Z")

</div>

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

---

<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:** [16 December 2018 16:11 UTC](https://discourse.nodered.org/t/convert-word-to-bool-to-word/5852/5 "2018-12-16T16:11:56Z")

</div>

This may help  
[https://www.w3schools.com/js/js\_bitwise.asp](https://www.w3schools.com/js/js_bitwise.asp)

---

<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:** [16 December 2018 16:17 UTC](https://discourse.nodered.org/t/convert-word-to-bool-to-word/5852/6 "2018-12-16T16:17:22Z")

</div>

> [@martinschki](#):
>
> So I need the bits addressable throughout node red, not just in a function

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.

---

<div class="post-metadata">

**Author:** ![martinschki](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/martinschki/32/737_2.png) [@martinschki](https://discourse.nodered.org/u/martinschki)\
**Post date:** [16 December 2018 16:22 UTC](https://discourse.nodered.org/t/convert-word-to-bool-to-word/5852/7 "2018-12-16T16:22:45Z")

</div>

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?

---

<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:** [16 December 2018 16:24 UTC](https://discourse.nodered.org/t/convert-word-to-bool-to-word/5852/8 "2018-12-16T16:24:22Z")

</div>

> [@martinschki](#):
>
> how do I get those 16 bits back into on dec value at the end of the flow?

A bit of javascript
