# How to set bits in a variable

**URL:** <https://discourse.nodered.org/t/how-to-set-bits-in-a-variable/38156>\
**Category:** General\
**Created:** [28 December 2020 20:30 UTC](https://discourse.nodered.org/t/how-to-set-bits-in-a-variable/38156 "2020-12-28T20:30:20Z")\
**Posts on this page:** 1\
**Showing post:** 2

<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:** [28 December 2020 20:56 UTC](https://discourse.nodered.org/t/how-to-set-bits-in-a-variable/38156/2 "2020-12-28T20:56:11Z")

</div>

> [@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) { …

Any good?

---

_[View the full topic](https://discourse.nodered.org/t/how-to-set-bits-in-a-variable/38156)._
