IEEE 754 float representation of a number
Greg Ewing
see_reply_address at something.invalid
Mon Dec 9 20:00:10 EST 2002
tommys wrote:
> '\x40\x42\x8f\x5c' (IEEE 754 format)
>
> but instead
>
> '@B\x8f\\' was returned.
Dennis Lee Bieber wrote:
> You likely have the desired bit pattern, just that some bytes in the
> pattern have printable representations, and hence were displayed with
> them rather than a \x escape.
Just to check that:
Python 2.2 (#1, Jul 11 2002, 14:19:37)
[GCC 3.0.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import struct
>>> s = struct.pack('>f',3.04)
>>> s
'@B\x8f\\'
>>> for c in s:
... print "%02X" % ord(c),
...
40 42 8F 5C
So, they're the right bytes!
--
Greg Ewing, Computer Science Dept,
University of Canterbury,
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg
More information about the Python-list
mailing list