# How can I convert 16 boolean values to an int16 value?

**URL:** https://discourse.nodered.org/t/how-can-i-convert-16-boolean-values-to-an-int16-value/86090
**Category:** General
**Tags:** function-node
**Created:** [3 March 2024 11:40 UTC](https://discourse.nodered.org/t/how-can-i-convert-16-boolean-values-to-an-int16-value/86090 "2024-03-03T11:40:32Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![DiegoSB13](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/diegosb13/32/88849_2.png) [@DiegoSB13](https://discourse.nodered.org/u/DiegoSB13)
#### Post date: [3 March 2024 11:40 UTC](https://discourse.nodered.org/t/how-can-i-convert-16-boolean-values-to-an-int16-value/86090/1 "2024-03-03T11:40:32Z")

</div>

I have 16 boolean variables that I want to send like an int16 type value.  
Is it possible to do it with a function node? How?

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [3 March 2024 12:07 UTC](https://discourse.nodered.org/t/how-can-i-convert-16-boolean-values-to-an-int16-value/86090/2 "2024-03-03T12:07:37Z")

</div>

> [@DiegoSB13](#):
>
> Is it possible to do it with a function node?

Yes.

How are these 16 boolean values stored? In named properties of an object? in an array? are they actual bools or strings or ones and zeros? etc etc (the devil is in the detail)

for example: an array could be processed like this:

```auto
let booleanArray = msg.payload

// test data for demonstration purposes (delete me)
booleanArray = [true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false]

msg.payload = booleanArray.reduce((acc, currentValue, index) => {
    return acc | (currentValue ? 1 << index : 0)
}, 0);

return msg

```

---

<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: [1 June 2024 12:08 UTC](https://discourse.nodered.org/t/how-can-i-convert-16-boolean-values-to-an-int16-value/86090/3 "2024-06-01T12:08:20Z")

</div>

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