# How to create a UNION of BOOL\[16\] and WORD

**URL:** https://discourse.nodered.org/t/how-to-create-a-union-of-bool-16-and-word/82665
**Category:** General
**Created:** [6 November 2023 22:33 UTC](https://discourse.nodered.org/t/how-to-create-a-union-of-bool-16-and-word/82665 "2023-11-06T22:33:03Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Sysmac](https://avatars.discourse-cdn.com/v4/letter/s/48db29/32.png) [@Sysmac](https://discourse.nodered.org/u/Sysmac)
#### Post date: [6 November 2023 22:33 UTC](https://discourse.nodered.org/t/how-to-create-a-union-of-bool-16-and-word/82665/1 "2023-11-06T22:33:03Z")

</div>

Hello all,  
new to Node-Red.

I would like to create a union connecting an array of bool [16] and a word (hex) then convert the word to a string. Any ideas? so 0000000000001100 -\> 0000000C -\> "0000000C"

Thank you for your time.

---

<div class="post-metadata">

### Author: ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)
#### Post date: [7 November 2023 09:14 UTC](https://discourse.nodered.org/t/how-to-create-a-union-of-bool-16-and-word/82665/2 "2023-11-07T09:14:16Z")

</div>

Just checking, your 16bit binary number would normally be reduced to a 4digit hex number i.e 000C (as each hex digit represents 4 bits)

Would it it be OK to do that or do you really need "0000000C"?

---

<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: [7 November 2023 15:58 UTC](https://discourse.nodered.org/t/how-to-create-a-union-of-bool-16-and-word/82665/3 "2023-11-07T15:58:47Z")

</div>

Could you feed your two values into a debug node and show us what you see please. That will ensure there is no confusion. The sort of confusion there may be is whether the WORD value is a String or a Number. Also whether you mean true/false for your bools or 1/0 (which are actually Numbers not booleans).

---

<div class="post-metadata">

### Author: ![Sysmac](https://avatars.discourse-cdn.com/v4/letter/s/48db29/32.png) [@Sysmac](https://discourse.nodered.org/u/Sysmac)
#### Post date: [7 November 2023 22:35 UTC](https://discourse.nodered.org/t/how-to-create-a-union-of-bool-16-and-word/82665/4 "2023-11-07T22:35:43Z")

</div>

Sorry for the lack of detail. I am connecting my PC running Node-Red to my RFID controller via serial.  
The Omron V640 system has this as the protocol  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/d/8d5369161c54ff4a142a2623fe9958978049b323.png)

The 'Node No', 'Command Code' and 'parameter' sections make up a string.  
I have already taken care of the preamble and postamble .

I was hoping to use the dashboard tools to have a switch for each page of a tag to read and union those to a DWORD (sorry for my initial mistake) or eight digits then convert to a string for the 8 characters  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/0/a0161356cd2e1c383fb40f402566db2af2212eab.png)

I have done this in my Omron NX102 PLC already and wanted to offer a solution for any customers using Node-Red versus a PLC. The PLC has a built-in capability to create a union of BOOL[32] and DWORD

So, by assigning a switch to bit 2 and another to bit 3 (designating tag pages 1 & 2 the rest off) this would result in a DORD of 0000000C then convert to a 8 character string to basically CONCAT NodeNo, Command, Parameter

Hope this helps.

---

<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: [8 November 2023 09:53 UTC](https://discourse.nodered.org/t/how-to-create-a-union-of-bool-16-and-word/82665/5 "2023-11-08T09:53:24Z")

</div>

As I asked,

> [@Colin](#):
>
> Could you feed your two values into a debug node and show us what you see please.

Edit: And tell us what you expect to get out, given that input data.

---

<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: [7 January 2024 09:54 UTC](https://discourse.nodered.org/t/how-to-create-a-union-of-bool-16-and-word/82665/6 "2024-01-07T09:54:26Z")

</div>

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