Decoder Help with bit shifting

No, never - it makes things even larger.

The conversion of values to an unsigned integer as demonstrated by @AndyG is the standard recommended technique. Taking things further by reducing from, say 16 bits to 12 and then sharing the other four bits is entirely feasible but does make for code that needs to be well tested & understood. Using a byte for on’s & off’s of digital devices is relatively straightforward coding and if you are writing firmware should be doable.

But if you have a float value of temp at 21.7 degC for instance, that’s either 4 bytes as the float which can be decoded at the back end, or with an appropriate offset could be just one byte of if it had two decimal places then it would be two bytes using the scheme above. But as soon as you start using strings you make the payload much bigger. So 21.75 deg C would need at least 6 bytes, four for the digits, one for the decimal and you will need a delimiter so you can tell where one reading ends & the next one starts.

Try reading https://www.thethingsnetwork.org/docs/devices/bytes/ - the pink warning box does not apply to this general document.

2 Likes