| Endian test | ||||||||||||||
| main () | big-endian | little-endian | ||||||||||||
| { | Address | Contents | ||||||||||||
| int i = 0x1234abcd, n; | 1000 | 12 | cd | |||||||||||
| unsigned char * byte = (unsigned char *) &i; | 1001 | 34 | ab | |||||||||||
| 1002 | ab | 34 | ||||||||||||
| for (n = 0; n < 4; n++) | 1003 | cd | 12 | |||||||||||
| printf ("%x ", *(byte + n)); | 1004 | |||||||||||||
| 1005 | ||||||||||||||
| return 0; | 1006 | |||||||||||||
| } | 1007 | |||||||||||||
| Why unsigned char? | ||||||||||||||
| Output (IBM PC): | ||||||||||||||
| cd ab 34 12 | ||||||||||||||
| Output (Sun): | ||||||||||||||
| 12 34 ab cd | ||||||||||||||