I have an little endian list value in python, I get with serial line.
I get this value as a byte like this:
JavaScript
x
2
1
[0, 0, 52, 66]
2
How can I convert this 4 byte (little endian) value to float ?
Advertisement
Answer
If the float is in IEEE754 format (which it very likely is), you can convert your list of numbers to a byte array and then use struct.unpack
to unpack it:
JavaScript
1
4
1
import struct
2
ba = bytes([0, 0, 52, 66])
3
print(struct.unpack('<f', ba)[0]) # prints 45.0
4