Hex:[0A][52][08][01][01][01][00][CD][21][02][59]
0 [0A]
1 [52] Packettype = TEMP_HUM
2 [08] subtype = TH8 -
3 [01] Sequence nbr = 1
4/5 [01][01] ID = 257
6/7 [00][CD] Temperature = 20.5 °C
8 [21] Humidity = 33
9 [02] Status = Dry
10 [5] *nibble Signal level = 5
11 [9] *nibble Battery = OK
So I get 11 bytes (Hex) in over the serial port. I assigned all the bytes to a byte array so that I can use them later.
I have two qestions:
1] How can I combine the 4 & 5 bytes back together in Java (I am presuming in an INT) ? 2] How can you extract 10 and 11 or the High and Low nibbles of the last byte ?
[FROM COMMENTS BELOW] Example Byte: High[0101][0110]Low lowNibble = yourbyte & 0x0f; 01010110 & 0x0f (00001111) = 00000110
highNibble = yourByte >>>> 4
01010110 >>> 4 = 00000101
IF you use this Example Byte: High[1101][0110]Low
highNibble = yourByte >>> 4
11010110 >>> 4 = 00000101
Because >>> removes the signed bit.