Blog Archive

Big Endian versus Little Endian

Big-endian means that the most significant byte is stored at the lowest memory address
0x12345678
(low address--->high address)

Read Wikipedia Page: http://en.wikipedia.org/wiki/Endianness



C program to find out whether a machine is big endian or little endian
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#include 
main () {
int i = 0x12345678;
if (*(char *)&i == 0x12)
printf ("Big endian\n");
else if (*(char *)&i == 0x78)
printf ("Little endian\n");
}

Is endian-ness bit level /byte-level/word-level?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
On a byte addressed machine it is byte level.


Examples of CPU Architectures
~~~~~~~~~~~~~~~~~~~~~~~
x86 processors use the little-endian format (sometimes called the Intel format).

Motorola processors have generally used big-endian. PowerPC (which includes Apple's Macintosh line prior to the Intel switch) and System/370 also adopt big-endian. SPARC historically used big-endian, though version 9 is bi-endian



Why different processor architectures choose different endian-ness? Is there any advantage of one over other?

No comments: