Endianness

Last edit

Changed: 6,7c6,10

< The Sockets API provides the functions ''htonl()'' and ''htons()'' for respectively 32-bits and 16-bits integers.
< The standard serial port is 'little-endian' in that it serializes with the least significant bit first.

to

> There are several solutions.
> * The XDR format specifies a number of data types in a platform independent manner. There is probably an XDR library for your programming language available.
> *
The Sockets API provides the functions ''htonl()'' and ''htons()'' for respectively 32-bits and 16-bits integers.
> Note:
> *
The standard serial port is 'little-endian' in that it serializes with the least significant bit first.


Endianness

Refers to the ordering of bytes in memory. Processor-, not OS-dependent.

Big-endian machines store integers (two bytes) with the "big end" in the lower address. Example: Sun Sparc-based machines. Little-endian machines store integers with the "little end" in the lower address. Example: x86.

So when you write an integer to a file on a big-endian box and you read the same file on a little-endian box, you have an error. Thus, some file formats specify whether they're big- or little-endian (BMP specifies little-endian, CCSDS specifies big-endian).

The same error also occurs when you write integers to a socket on a big-endian box and read the same socket on a little-endian box. That's why the Internet Protocol specifies that all numeric values must be in "network byte order", which is big-endian.

There are several solutions.

Note: