Endian Conversion
Description |
|---|
To swap the byte order from Little Endian to Big Endian and vice versa this can be done like this: •16 Bit value (unsigned short): x = ((y & 0xff) << 8) | ((y & 0xff00)>> 8) •32 Bit value (unsigned int): x = ((y & 0xff) << 24) | ((y & 0xff00) << (8 0xff0000)>> 8) | ((y & 0xff000000) >> 24) |
Only little Endian is used.
The endianness between platforms can be managed with the functions pack() and unpack() of the struct module. The byteswap() of array module can help too. The usage depends on desired goals.