3 byte network ordered int, How To ?

John Machin sjmachin at lexicon.net
Thu Jan 7 01:17:57 CET 2010


On Jan 7, 5:33 am, Matthew Barnett <mrabarn... at mrabarnett.plus.com>
wrote:
> mudit tuli wrote:
> > For a single byte, struct.pack('<B',<int>)
> > For two bytes, struct.pack('<H',<int>)
> > what if I want three bytes ?
>
> Four bytes and then discard the most-significant byte:
>
> struct.pack('<I', <int>)[ : -1]

AARRGGHH! network ordering is BIGendian, struct.pack('<..... is
LITTLEendian



More information about the Python-list mailing list