Strange problem with structs Linux vs. Mac

Martin Blume mblume at freesurf.ch
Sun Mar 16 13:23:41 EDT 2008


"jasonwiener" schrieb
> 
> I am having a VERY odd problem with unpacking right now. 
> I'm reading data from a binary file and then using a very 
> simple struct.unpack to get a long.  Works fine on my MacBook,
> but when I push it to a Linux box,it acts differently and 
> ends up pewking.
> [...]
> 
> the data looks to be the same, but the unpacking seems to 
> treat it differently.
> 
Probably little-endian vs. big-endian issue:

>>> s
'\x1e\xc6\xf3\xb4'
>>> struct.unpack('<I', s)
(3035874846L,)
>>> struct.unpack('>I', s)
(516354996L,)

See help(struct) for further information.

This seems to imply that the Mac, although running now on Intel
processors, is still big-endian.

HTH
Martin




More information about the Python-list mailing list