# Create 16 single bit input to a 16bit modbus value

**URL:** <https://discourse.nodered.org/t/create-16-single-bit-input-to-a-16bit-modbus-value/56938>\
**Category:** General\
**Created:** [19 January 2022 22:07 UTC](https://discourse.nodered.org/t/create-16-single-bit-input-to-a-16bit-modbus-value/56938 "2022-01-19T22:07:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rogier](https://avatars.discourse-cdn.com/v4/letter/r/ecc23a/32.png) [@rogier](https://discourse.nodered.org/u/rogier)\
**Post date:** [19 January 2022 22:07 UTC](https://discourse.nodered.org/t/create-16-single-bit-input-to-a-16bit-modbus-value/56938/1 "2022-01-19T22:07:10Z")

</div>

i want to convert 16 time single bit into one 16 bit value for my modbus project. when 1 bit input change the 16 bit value has also to change. There has to be a memory of all the states of the inputs... has somebody an solution?

---

<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:** [19 January 2022 22:45 UTC](https://discourse.nodered.org/t/create-16-single-bit-input-to-a-16bit-modbus-value/56938/2 "2022-01-19T22:45:29Z")

</div>

This should get you started...

> [@Node-red-contrib-remote-io, digital output for joining bool to word](https://discourse.nodered.org/t/node-red-contrib-remote-io-digital-output-for-joining-bool-to-word/11798/2):
>
> If you mean combining bits to make a WORD value - its just basic math functionality of the programming language. e.g.... //Get bit function getBit(number, bitPosition) { return (number & (1 \<\< bitPosition)) === 0 ? 0 : 1; } //Set Bit function setBit(number, bitPosition) { return number | (1 \<\< bitPosition); } //Clear Bit function clearBit(number, bitPosition) { const mask = ~(1 \<\< bitPosition); return number & mask; } //Update Bit function updateBit(number, bitPosition, bitValue) { …

---

<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:** [20 March 2022 22:45 UTC](https://discourse.nodered.org/t/create-16-single-bit-input-to-a-16bit-modbus-value/56938/3 "2022-03-20T22:45:38Z")

</div>

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