Little or Big?

Big endian and little endian. The endian-ness of a computer determines how it stores multi-byte data in memory. Consider the 4 byte integer 0x40302010. This is the hex representation of the integer 1076895760. Each byte can store 2 hex digits. So the number 0x40302010 would have to be stored in 4 bytes. If we were to store this number at memory location 100, would we store 40 at 100, 30 at 101, 20 at 102 and 10 at 103 or would be do it the opposite way – 10 at 100, 20 at 101, 30 at 102 and 40 at 103? Big endian computers do it the first way and little endian computers do it the second way.

Here is a pictorial representation of this. The memory address increase from left to right.

Big endian
100 ->
——————————
| 40 | 30 | 20 | 10 | —
——————————

Little endian
100 ->
——————————
| 10 | 20 | 30 | 40 | —
——————————

This is not a hard concept to grasp. But I could never remember which is which. Is big endian the one where we store the MSB first or is it the other way around. I always have to look it up.

Today, while waiting for a deployment to finish (perfect excuse to slack off now that compiling doesn’t take a long time), I was browsing some websites and I stumpled on the endian-ness of computers. I couldn’t remember which was which and I had to look it up. Again. Suddenly a flash of insight hit me – Little endian stores LSB (Least Significant Byte) in the Little address (smaller address). LLL. Little endian – LSB – Little address.

I think I have it etched in my memory now. This is a well known memory technique but its name escapes me now (oh the irony).

Leave a Reply

Your email address will not be published. Required fields are marked *