C Programming - Byte Order

Little Endian Byte Order:
"Little Endian" means that the low-order byte of the number is stored in memory at the lowest address, and the high-order byte at the highest address.

eg. long int i = 0x12345678; /* assuming long int has 4 bytes */

0x8000490: 0x78
0x8000491: 0x56
0x8000492: 0x34
0x8000493: 0x12

Big Endian Byte Order:
"Big Endian" means that the high-order byte of the number is stored in memory at the lowest address, and the low-order byte at the highest address.

eg. long int i = 0x12345678;

0x8000490: 0x12
0x8000491: 0x34
0x8000492: 0x56
0x8000493: 0x78

Function to find whether an architecture is Big or Little Endian:

char endian() /* 0 - Big Endian, 1 - Little Endian */
{
long i = 1;
return *((char *) &i);
}

Labels:


About this entry