why struct.pack behave like this

Xie&Tian mftian at gmail.com
Thu May 20 08:56:07 EDT 2010


Hi

When I use struct to pack binary data, I found this interesting behaviour:

>>> import struct
>>> struct.pack('B', 1)
'\x01'
>>> struct.pack('H', 200)
'\xc8\x00'
>>> struct.pack('BH',1, 200)
'\x01\x00\xc8\x00'
>>> struct.calcsize('BH')
4

Why does "struct.pack('BH',1, 200)" come out with an extra "\x00"?


-- 
Luyun Xie
http://magefromhell.blogspot.com/
(http://blog.hellmage.info/)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100520/82f02eb7/attachment.html>


More information about the Python-list mailing list