Help need with converting Hex string to IEEE format float

Christos TZOTZIOY Georgiou tzot at sil-tec.gr
Wed Dec 15 04:04:33 EST 2004


On Tue, 14 Dec 2004 16:57:02 +0100, rumours say that "Fredrik Lundh"
<fredrik at pythonware.com> might have written:

>how about:
>
>    # convert to byte string
>    import struct
>    s = "".join([chr(int(c, 16)) for c in x])
>    v = struct.unpack("!f", s)

I think that the third line in the snippet above could also be:

s = "".join(x).decode("hex")

I am not sure I remember in which version of Python the hex codec was
added, but it is handy.
-- 
TZOTZIOY, I speak England very best.
"Be strict when sending and tolerant when receiving." (from RFC1958)
I really should keep that in mind when talking with people, actually...



More information about the Python-list mailing list