hex string to floating point (newbie)

Alex Martelli aleax at aleax.it
Mon Mar 17 14:54:45 CET 2003

zif wrote:

> I would appreciate if somebody could help me solve my problem:
> I need to translate a hex string '3f8ccccd' to it's
> floating point value.

Not sure, offhand, if there's a more direct way, one way is
going through an int, then module struct -- packing the "int"
into a 4-byte string, then unpacking the latter as a float:

>>> x='3f8ccccd'
>>> struct.unpack('f',struct.pack('i',int(x,16)))


More information about the Python-list mailing list