# Bit Strip from Int

**URL:** <https://discourse.nodered.org/t/bit-strip-from-int/67221>\
**Category:** General\
**Created:** [1 September 2022 16:23 UTC](https://discourse.nodered.org/t/bit-strip-from-int/67221 "2022-09-01T16:23:07Z")\
**Posts on this page:** 8\
**Page:** 2

<div class="post-metadata">

**Author:** ![HansZnarf](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hansznarf/32/70215_2.png) [@HansZnarf](https://discourse.nodered.org/u/HansZnarf)\
**Post date:** [2 September 2022 12:52 UTC](https://discourse.nodered.org/t/bit-strip-from-int/67221/21 "2022-09-02T12:52:29Z")

</div>

Move did it, Thanks!

---

<div class="post-metadata">

**Author:** ![HansZnarf](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hansznarf/32/70215_2.png) [@HansZnarf](https://discourse.nodered.org/u/HansZnarf)\
**Post date:** [2 September 2022 13:06 UTC](https://discourse.nodered.org/t/bit-strip-from-int/67221/22 "2022-09-02T13:06:18Z")

</div>

TEAM: Any ideas on how to reverse the process? The outputs are handled in the same way. Also can you explain how that code worked to strip out the bits. Cannot follow the meaning of (msg.payload \>\> 1) & 1. Thanks Hans

---

<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:** [2 September 2022 13:25 UTC](https://discourse.nodered.org/t/bit-strip-from-int/67221/23 "2022-09-02T13:25:56Z")

</div>

That means to shift it right one bit and then AND it with the value 1, which clears down any other bits.

If you want to set a particular bit then you just have to use the bitwise OR (`|`) to set the appropriate bit. However, you would probably be better to use the buffer parser node as suggested earlier by @Steve-Mcl, which I believe can both decode and encode such values.

---

<div class="post-metadata">

**Author:** ![HansZnarf](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hansznarf/32/70215_2.png) [@HansZnarf](https://discourse.nodered.org/u/HansZnarf)\
**Post date:** [2 September 2022 16:51 UTC](https://discourse.nodered.org/t/bit-strip-from-int/67221/24 "2022-09-02T16:51:11Z")

</div>

Colin: Many thanks. Found a 16 bit split function that does what we need in a simple way.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/3/3371ef2f5ab732283579b030b2a9984c1073ddcb.png)  
Works very well

---

<div class="post-metadata">

**Author:** ![iiot2k](https://avatars.discourse-cdn.com/v4/letter/i/8baadc/32.png) [@iiot2k](https://discourse.nodered.org/u/iiot2k)\
**Post date:** [2 September 2022 18:15 UTC](https://discourse.nodered.org/t/bit-strip-from-int/67221/25 "2022-09-02T18:15:31Z")

</div>

Here is a litte JavaScript program with suprise of bit 31: 🙂

```nohighlight
console.log(0x40000000 >> 30);
console.log(0x80000000 >> 31);

```

The result should be on both 1.  
Or am I thinking wrong?  
What would you expect for an output?

---

<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:** [2 September 2022 20:38 UTC](https://discourse.nodered.org/t/bit-strip-from-int/67221/26 "2022-09-02T20:38:09Z")

</div>

As I posted earlier, you need to use `>>>`

---

<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 September 2022 06:28 UTC](https://discourse.nodered.org/t/bit-strip-from-int/67221/27 "2022-09-03T06:28:56Z")

</div>

And if you use buffer-parser, you can request bit 69 or 128 or 3456 and it will always get the right value.

---

<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:** [17 September 2022 06:29 UTC](https://discourse.nodered.org/t/bit-strip-from-int/67221/28 "2022-09-17T06:29:23Z")

</div>

Closed on 17 September 2022 06:29 UTC

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

[Previous page](https://discourse.nodered.org/t/bit-strip-from-int/67221.md?page=1)
