I have a binary file that I have to parse and I'm using Python. Is there a way to take 4 bytes and convert it to a single precision floating point number?
Add a bit of demonstration code and I'll upvote.
John Mulder
2009-01-09 05:44:48
+9
A:
>>> import struct
>>> struct.pack('f', 3.141592654)
'\xdb\x0fI@'
>>> struct.unpack('f', '\xdb\x0fI@')
(3.1415927410125732,)
>>> struct.pack('4f', 1.0, 2.0, 3.0, 4.0)
'\x00\x00\x80?\x00\x00\x00@\x00\x00@@\x00\x00\x80@'
ΤΖΩΤΖΙΟΥ
2008-09-16 14:59:37
A:
Hi everybody, how could I do the inverse operation? i.e, in my case, i need to convert a float to a 4 byte array?
Javier
2010-07-02 14:18:57