<<< Little Endian Example     Index     Data Allocation Directives >>>

6. Big and Little Endian

  • Different processors store multibyte integers in different orders in memory.

  • There are two popular methods of storing integers: big endian and little indian.

  • Big endian method is the most natural:

    • the biggest (i.e. most significant) byte is stored first, then the next biggest, etc.

  • IBM mainframes, most RISC processors and Motorola processors all use this big endian method.

  • However, Intel-based processors use the little endian method, in which the least significant byte is stored first.

  • Normally, the programmer does not need to worry about which format is used, unless

    1. Binary data is transfered between different computers e.g. over a network.

      • All TCP/IP headers store integers in big endian format (called network byte order.)

    2. Binary data is written out to memory as a multibyte integer and then read back as individual bytes or vise versa.

  • Endianness does not apply to the order of array elements.

  • See also: wikipedia article about endianness .

      Byte sequence order
    Data type Value(*) Big endian Little endian
    12 34
    34 12
    00 47 d5 a8
    a8 d5 47 00
    56 78 9a bc
    bc 9a 78 56
  • (*) All values shown in base 16.

  • Big Endian:

      Big Endian

  • Little Endian:

      Little Endian

<<< Little Endian Example     Index     Data Allocation Directives >>>