This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author termim
Recipients termim
Date 2008-11-06.17:30:42
SpamBayes Score 3.0168653e-08
Marked as misclassified No
Message-id <1225992644.3.0.448967011031.issue4270@psf.upfronthosting.co.za>
In-reply-to
Content
pack/unpack behavior changes unexpectedly depending on the byte order:

l:/tmp >uname -pmiovs
Linux #1 SMP 2008-10-14 22:17:43 +0200 x86_64 x86_64 x86_64 GNU/Linux
l:/tmp >python
python
Python 2.5.1 (r251:54863, Aug  1 2008, 00:35:20) 
[GCC 4.2.1 (SUSE Linux)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import struct
import struct
>>> struct.pack(">L",0xdeadbeef)
struct.pack(">L",0xdeadbeef)
'\xde\xad\xbe\xef'
>>> struct.pack("L",0xdeadbeef)
struct.pack("L",0xdeadbeef)
'\xef\xbe\xad\xde\x00\x00\x00\x00'
>>> struct.pack("<L",0xdeadbeef)
struct.pack("<L",0xdeadbeef)
'\xef\xbe\xad\xde'
>>> 

The length of the result above is 8 when no byte order is specified
and 4 when it is.

Another example:

>>> struct.pack("L",0xdeadbeef00000000)
'\x00\x00\x00\x00\xef\xbe\xad\xde'
>>> struct.pack("<L",0xdeadbeef00000000)
'\x00\x00\x00\x00'
>>> struct.pack("!L",0xdeadbeef00000000)
'\x00\x00\x00\x00'
>>> struct.pack("!L",0x12345678deadbeef)
'\xde\xad\xbe\xef'
>>> struct.pack("L",0x12345678deadbeef)
'\xef\xbe\xad\xdexV4\x12'
>>> 

Last results look strange.
History
Date User Action Args
2008-11-06 17:30:44termimsetrecipients: + termim
2008-11-06 17:30:44termimsetmessageid: <1225992644.3.0.448967011031.issue4270@psf.upfronthosting.co.za>
2008-11-06 17:30:43termimlinkissue4270 messages
2008-11-06 17:30:42termimcreate