Hey all, I'm having a little trouble packing a numpy.float32 using the struct.pack function.
f32 = 38.2
struct.pack('f', f32)
The hexadecimal representation of 38.2, in 32 bits, is 0x4218CCCD. however, when I use the python terminal to 开发者_如何学Gorun the preceding code (after importing the appropriate modules), the output is:
'\xcd\xcc\x18B'
I don't understand why it's leaving out the \x42 that should be before the B.
I am running 32 bit version of python 2.7 on a 64 bit machine. Any ideas?
Thanks in advance.
You got what you wanted.
>>> "\x42" == "B"
True
\x42
corresponds to ASCII B
.
精彩评论