COHERENT manpages

This page displays the COHERENT manpage for byte ordering [Machine-dependent ordering of bytes].

List of available manpages
Index


byte ordering -- Definition

Machine-dependent ordering of bytes

Byte ordering is the order in which a given machine stores successive bytes
of a multibyte data item.  Different machines order bytes differently.

The following example displays a few simple examples of byte ordering:

main()
{
    union
    {
        char b[4];
        int i[2];
        long l;
    } u;
    u.l = 0x12345678L;

    printf("%x %x %x %x\n",
        u.b[0], u.b[1], u.b[2], u.b[3]);
    printf("%x %x\n", u.i[0], u.i[1]);
    printf("%lx\n", u.l);
}

When run on  ``big-endian'' machines, such as the M68000  or the Z8000, the
program gives the following results:

    12 34 56 78
    1234 5678
    12345678

As you can see, the order of bytes and words from low to high memory is the
same as is represented on the screen.

However, when  this program is  run on ``little-endian''  machines, such as
the PDP-11, you see these results:

    34 12 78 56
    1234 5678
    12345678

As  you can  see, the  PDP-11 inverts  the order of  bytes within  words in
memory.

Finally, when the program is run on the i8086 you see these results:

    78 56 34 12
    5678 1234
    12345678

The i8086 inverts both words and long words.

See Also

C language,
canon.h,
data formats,
Programming COHERENT