Cast operator | ||||||||||||||
Problem: given int i, access a particular byte | big-endian | little-endian | ||||||||||||
int i = 0x1234abcd; | Address | Contents | ||||||||||||
Is this big-endian or little-endian? How can we tell? | 1000 | 12 | cd | |||||||||||
By definition, if we look at the bits in i, the leftmost bits are | 1001 | 34 | ab | |||||||||||
0001 | 0010 | (big- or little-endian) | 1002 | ab | 34 | |||||||||
Value is independent of byte order | 1003 | cd | 12 | |||||||||||
1004 | ||||||||||||||
1005 | ||||||||||||||
1006 | ||||||||||||||
1007 | ||||||||||||||