BIG/LITTLE-ENDIANS

Cosme Furlong
WPI-ME/CHSLT


Generally, when representing data, the order of significance is such that the MSB (Most Significant Byte) is the leftmost, while the LSB (Least Significant Byte) is the rightmost.

When the order of significance is such that the MSB (Most Significant Byte) is the leftmost, while the LSB (Least Significant Byte) is the rightmost, the data format is said to be Little Endian.  When the order of significance is such that the LSB (Least Significant Byte) is the leftmost, while the MSB (Most Significant Byte) is the rightmost, the data format is said to be Big Endian, see the following figure,

Big and little-endian DATA formats




For example, consider the number 1025 (2 to the tenth power plus one) stored in a 4-byte integer:

                 00000000 00000000 00000100 00000001
 

Address
Big-Endian
representation
of 1025
Little-Endian
representation
of 1025
00 
01
02
03
00000000
00000000
00000100
00000001 
 00000001
00000100
00000000
00000000 

Many mainframe computers, particularly IBM mainframes, use a big-endian architecture.  Most modern computers, including PC's, use the little-endian system.  The PowerPC system is bi-endian because it can understand both systems.

Converting data between the two systems is sometimes referred to as the NUXI problem.  Imagine the word UNIX stored in two 2-byte words. In a Big-Endian systems, it would be stored as UNIX.  In a little-endian system, it would be stored as NUXI.

Note that the example above shows only big- and little-endian byte orders.  The bit ordering within each byte can also be big- or little-endian, and some architectures actually use big-endian ordering for bits and little-endian ordering for bytes, or vice versa.

For structures declared in a high-level language, the order of bytes in memory will differ depending on the byte ordering and the particular data type, for instance
 
C-code
Big Endian
Memory Contents
Little Endian
Memory Contents
struct {
        long a;
        short b[2];
        char c[4];
        } S1 = {
            0x12345678,
            0x1234,0x5678,
            "ABC" 
        };
/* Big endian
 /*      12 34 56 78
 /*      12 34 56 78
 /*      41 42 43 00 
Little Endian */
78 56 34 12     */
34 12 78 56     */
41 42 43 00     */



Back to top
Back to ME-593N page


[Main]



[Mechanical Engineering Department]


[CHSLT / NEST Labs]