I got two bytes:
byte[0]
is 0000 0000
byte[1]
is 1000 0000
I would like to put them together and make one float value of them. So the result should be 128 is decimal and 0000 0000 1000 0000 in binary. Not negative because of the leading zero.
My solution so far is this approach:
float f = (bytes[0] << 8 | bytes[1]);
But this will result in a value of minus 128 for value f. It's because of the 2s complement i guess. Therefore byte[1]
will be interpreted as negative. How can I just see the leading bit of byte[0]
as the bit for negative/positive?