1

I have an little endian list value in python, I get with serial line.

I get this value as a byte like this:

[0, 0, 52, 66]

How can I convert this 4 byte (little endian) value to float ?

2
  • can you provide the expected output for clarity? Commented Nov 24, 2021 at 13:50
  • You should take a look at the struct module Commented Nov 24, 2021 at 13:54

1 Answer 1

3

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:

import struct
ba = bytes([0, 0, 52, 66])
print(struct.unpack('<f', ba)[0]) # prints 45.0
Sign up to request clarification or add additional context in comments.

1 Comment

this is the answer i was looking for thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.