Byte Ordering

When your network application communicates across the network, it talks to many hosts. These hosts might be main frames, departmental servers, desktop computers, personal digital assistants, or the routers and switches that control Internet traffic. They may run Windows, MacOS, any of the myriad flavors of Unix, or some proprietary operating system. In this sea of hosts, there are many different processors and operating systems, all of which deal with computing slightly differently.

One of the ways in which processors differ is the representation of multibyte integers (i.e., 16- and 32-bit integers). Some processors are Big-Endian, which represent these values with the most significant byte (MSB) stored on the leftmost byte. Others are Little-Endians, which store the MSB on the far right.

Let’s say we are trying to represent the hex number 1234. The most significant byte for this value is 1 and the least significant byte is 4. A Big-Endian processor represents this as:

1                        2                        3                        4

A Little-Endian processor, on the other hand, represents this as:

4                        3                        2                        1

When a Big-Endian host communicates with a Little-Endian host without translation, there are problems. Let’s say we move a file from a Big-Endian MacIntosh to a Little-Endian PC. If the file contains the number 1234h, the PC interprets it as 4321h. It would be unreadable.

Tip

The terms “Big-Endian” and “Little-Endian” come from Jonathan Swift’s Gulliver’s Travels. In the land of Lilliput, a fierce debate raged between the ...

Get Palm OS Network Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.