Define Big/Little Endian ( was: Re: RISC Mach...)
M. J. Halloran II McDonnell Douglas M&E
halloran at mdcbbs.com
Fri Feb 2 17:49:02 AEST 1990
In article <6200024 at ux1.cso.uiuc.edu>, phil at ux1.cso.uiuc.edu writes:
> Another problem you can encounter when dealing with data structure formats
> imposed by hardware, particularly external hardware, is the byte order.
> An example is handling TCP and IP headers. The exact data structure is
> defined very specifically, but making code that can deal with it AND be
> portable across big and little endian machines requires a lot of care.
--- ------ ------
Let's clerify...
> Such portable code may not be the most optimal depending on how it is
> done.
>
> --Phil Howard, KA9WGN--
> <phil at ux1.cso.uiuc.edu>
These define how bytes within words are ordered.
Big endian: Big end first (MSB)(LSB).
Little endian: Little end first (LSB)(MSB).
ie:
typedef union {
unsigned char bytes[2];
unsigned long word;
} INDIANS;
main() {
INDIAN indian;
indian.word = 0x1234;
if ( indian.bytes[0] == 0x12) /* is MSB at lower mem? */
puts ( "Big Endian\n");
else
puts ( "Little Endian\n");
}
More information about the Comp.lang.c
mailing list