Large and small ends of byte order, large ends of byte order
A 16-bit integer consisting of two bytes. There are two ways to store these two bytes in memory: one is to store the low byte at the starting address, which is calledSmall Terminal(Little-endian) byte order; the other is to store the high byte at the starting address. This method is calledBig End(Big-endian) byte order.
Network Programming, system design, and assembly may involve large-end and small-end issues.
The following simple C program can determine whether the machine you are using is a large terminal or a small terminal.
# Include <stdio. h> int main (int argc, char const * argv []) {union // use union to indicate data in different ways {short s; char c [sizeof (short)];} un; un. s = 0x0102; printf ("char is % lu byte \ n", sizeof (char); if (sizeof (short) = 2) {if (un. c [0] = 1) & (un. c [1] = 2) {printf ("big-endian \ n");} else if (un. c [0] = 2) & (un. c [1] = 1) {printf ("little-endian \ n");} else {printf ("unknown \ n ");}} else {printf ("sizeof (short) = % lu \ n", sizeof (short);} return 0 ;}
Reference: Unix Network Programming