TheThingsNetwork / arduino-node-lib

Arduino Library for The Things Node
MIT License
22 stars 26 forks source link

Fixed decoder function for negative temperatures #11

Closed samvanbrussel closed 6 years ago

samvanbrussel commented 6 years ago

When negative numbers in 2-complement get converted from 16-bit (Arduino) to 32-bit (JavaScript), the sign bit has to be at bit 0, not at bit 17, as it was with the old code, which implicitly padded 16 zeroes to the left. As a result, the negative number -1 returns 65535.

By prefixing a 16-bit negative number with 16 ones, the correct 32-bit 2-complement number is constructed.

CLAassistant commented 6 years ago

CLA assistant check
All committers have signed the CLA.