.TH "byte ordering" "" "" "Definition"
.PC "Machine-dependent ordering of bytes"
.PP
.B "Byte ordering"
is the order in which a given machine stores successive bytes of
a multibyte data item.
Different machines order bytes differently.
.PP
The following example displays a few simple examples of byte ordering:
.DM
main()
{
	union
	{
		char b[4];
		int i[2];
		long l;
	} u;
	u.l = 0x12345678L;
.DE
.DM
	printf("%x %x %x %x\en",
		u.b[0], u.b[1], u.b[2], u.b[3]);
	printf("%x %x\en", u.i[0], u.i[1]);
	printf("%lx\en", u.l);
}
.DE
.PP
When run on \*(QLbig-endian\*(QR machines, such as the M68000 or the Z8000,
the program gives the following results:
.DM
	12 34 56 78
	1234 5678
	12345678
.DE
.PP
As you can see, the order of bytes and words from low to high
memory is the same as is represented on the screen.
.PP
However, when this program is run on \*(QLlittle-endian\*(QR
machines, such as the PDP-11, you see these results:
.DM
	34 12 78 56
	1234 5678
	12345678
.DE
.PP
As you can see, the PDP-11 inverts the order of bytes within
words in memory.
.PP
Finally, when the program is run on the i8086 you see these results:
.DM
	78 56 34 12
	5678 1234
	12345678
.DE
.PP
The i8086 inverts both words and long words.
.SH "See Also"
.Xr "C language," c_languag
.Xr canon.h, canon.h
.Xr "data formats," data_form
.Xr "Programming COHERENT" programmi
