# Bit fields and bitwise operations

**URL:** https://discourse.nodered.org/t/bit-fields-and-bitwise-operations/72809
**Category:** General
**Created:** [28 December 2022 09:07 UTC](https://discourse.nodered.org/t/bit-fields-and-bitwise-operations/72809 "2022-12-28T09:07:07Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Graefe](https://avatars.discourse-cdn.com/v4/letter/g/ce7236/32.png) [@Graefe](https://discourse.nodered.org/u/Graefe)
#### Post date: [28 December 2022 09:07 UTC](https://discourse.nodered.org/t/bit-fields-and-bitwise-operations/72809/1 "2022-12-28T09:07:07Z")

</div>

I would like to represent the status (open/close) of multiple windows for further use (e.g. alarm system). My idea was to put the status of all devices in one bit field. A bit field seems to be very handy, especially if you want to make bitwise logical operations in order to change or read one of the bits.  
Strange to say NodeRed does not support fields natively, does it? So, what would you suggest alternatively? Otherwise I would try to realize that with function nodes/JS.  
Thanks  
Graefe

---

<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: [28 December 2022 13:45 UTC](https://discourse.nodered.org/t/bit-fields-and-bitwise-operations/72809/2 "2022-12-28T13:45:42Z")

</div>

> [@Graefe](#):
>
> My idea was to put the status of all devices in one bit field.

Welcome to the forum @Graefe

Why bother? Generally it would just complicate the code.

> [@Graefe](#):
>
> Strange to say NodeRed does not support fields natively

It isn't node-red that would have to support it, it is javascript.

---

<div class="post-metadata">

### Author: ![drmibell](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/drmibell/32/8424_2.png) [@drmibell](https://discourse.nodered.org/u/drmibell)
#### Post date: [29 December 2022 03:26 UTC](https://discourse.nodered.org/t/bit-fields-and-bitwise-operations/72809/3 "2022-12-29T03:26:33Z")

</div>

JavaScript does support [bitwise operations](https://www.w3schools.com/js/js_bitwise.asp), but with a bunch of clumsy conversions between 64-bit floating point and 32-bit signed integers. Unless your application can really benefit from logical or shift operations on binary numbers, it's probably not worth the bother.

---

<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: [27 February 2023 03:26 UTC](https://discourse.nodered.org/t/bit-fields-and-bitwise-operations/72809/4 "2023-02-27T03:26:54Z")

</div>

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