Decrypting messages for dummies

By the way:

While it will indeed return the correct value, using 0xFFFF<<24 is confusing, I feel. I wrote:

This is the same as:

var celciusInt = (bytes[0] & 0x80 ? 0xFFFF0000 : 0) | bytes[0]<<8 | bytes[1];

Above, handling 2 bytes from the payload, one needs to determine the value for the leftmost 2 bytes to get 32 bits. But in your case, when handling 3 bytes from the payload, you only need 1 extra byte to get 32 bits. Now, in JavaScript’s 32 bits processing for bitwise operators, your 0xFFFF<<24 indeed yields the 32 bits FF000000, not the 40 bits FFFF000000. But you can achieve the same with 0xFF<<24.

To be sure you understand bit shifting, see many more examples in Laird RS1xx - probably a question on bit shifting - #7 by arjanvanb and Payload Format / Decode for TM-901 / N1C2 sensor from KCS TraceME - #4 by arjanvanb.

(Aside: please see How do I format my forum post? [HowTo] about formatting code blocks, to avoid surprises with unwanted formatting, like happened in your first post before I edited that.)

1 Like