Changing endian format
David M. Wilson
dw-google.com at botanicus.net
Sat Jan 24 21:58:50 CET 2004
Amit Gaur <amitgaur at yahoo.com> wrote...
> Hi newbie to python here,
> I have a binary file and i need to change the endian format..little to big as well as vice versa..could anyone help me out.
If you use the struct module to read the file, this appears to be
handled for you.
Example (pack the value 1234 into an unsigned long in little endian,
then big endian format):
py> import struct
py> struct.pack('<L', 1234)
py> struct.pack('>L', 1234)
See also 'struct.unpack', 'socket.htons', and 'socket.htonl'.
More information about the Python-list