how to convert 4 bytes into a float ?
Jean-Baptiste PERIN
jb_perin at yahoo.fr
Tue Feb 8 05:53:12 EST 2005
Alex Martelli a écrit :
> Jean-Baptiste PERIN <jb_perin at yahoo.fr> wrote:
>
>
>>I read 4 bytes from a binary file.
>>
>>These bytes represent a floating point number (mantisse exponent form)
>>
>>How can I get a float from these bytes ?
>
>
> See the docs for module struct, specifically the struct.unpack function,
> if the float is in the binary format your machine expects (or possibly
> that but with the wrong endianity). If the float's binary format is
> different from what your machine uses, you're in for a lot of painful
> bit-twiddling.
>
>
> Alex
I'll have to handle Intel-PC, DEC-VAX and MIPS-SUN/SGI numbers
So I can't escape the painful bit-twiddling
Anyway, struct.unpack will undoubtedly be an incredibly valuable help
thank you very very very much ..
JiBé
More information about the Python-list
mailing list