Bit Strip from Int

Move did it, Thanks!

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

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.

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

Works very well

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

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?

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

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

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