# Reverse Engineering Temperatures (RS485 Bus)

I have the following hex byte data. Can someone help me reverse engineer the temperatures calculation?

``````ID
||
81 00 8c 00
82 00 aa 00
83 00 04 01
84 00 ff 00
85 00 21 04
``````

The first byte is the id! 81-84=1-4

One of the data is 14,0 C° and another one is 17,0 C°.

My tries:
- (Second Byte * 10) + (Third Byte *10/256)
- (Second Byte - 0x80) / 2
- (Second Byte / 2) - 0x80
- Second Byte * 100
- (Second Byte / 2) - 20

I would guess that this is raw (unencoded) data and every row is consisted of two 16 bit integers stored in little-endian order. This means that

``````temperature = (float)(b << 8 + b) / 10;
``````

where `b` is the third byte and `b` is the fourth.

So using the above formula, the data would yield the following temperatures:

``````81 00 8c 00; #Measurement 0x0081 - 14.0
82 00 aa 00; #Measurement 0x0082 - 17.0
83 00 04 01; #Measurement 0x0083 - 26.0
84 00 ff 00; #Measurement 0x0084 - 25.5
85 00 21 04; #Measurement 0x0085 - 105.7
``````

Update:

Here is a Python snippet which does the conversion given a string with space-separated hex values:

``````input = "81 00 8c 00"
byte_arr = input.split(" ")

for i in range(len(byte_arr)):
byte_arr[i] = int(byte_arr[i], 16)

measurement_id = byte_arr << 8 | byte_arr
temperature = (byte_arr << 8 | byte_arr) / 10.0

print("Measurement: %d" % measurement_id)
print("Temperature: %.2f C°" % temperature)
``````
• Thanks for your answer, Anton. Sorry for my delay. Can you explain this more for me. Specially "<<" I would like to use the code in python. If I use this I get 0.0 for "81 00 8c 00". Aug 8 '19 at 20:02
• The `<<` operator refers to bit-wise left shifting. I added an example how to use the formula in Python. Aug 9 '19 at 8:18