On 2005-01-15, Scott David Daniels <[EMAIL PROTECTED]> wrote:
>> I've read some bytes from a file and just now I can't interpret 4 bytes
>> in this dates like a real value.
> OK, here's the skinny (I used blocks & views to get the answer):
>
> import struct
> bytes = ''.join(chr(int(txt, 16)) for txt in '3F 8C CC CD'.split())
> struct.unpack('>f', bytes)
Just be careful. That doesn't work for all 32-bit IEEE floating
point values:
>>> import struct
>>> bytes = '\xff\xff\xff\xff'
>>> print struct.unpack('>f',bytes)
(-6.8056469327705772e+38,)
0xffffff is _not_ -6.8...e38. It's a NaN.
IIRC, it doesn't work for infinities either. I haven't tried
denormals.
--
Grant Edwards grante Yow! It's hard being
at an ARTIST!!
visi.com
--
http://mail.python.org/mailman/listinfo/python-list