ProAnswers.org

What is "little endian " and "big endian"?

2 Likes

Big Endian:

In big endian, you store the most significant byte in the smallest address. Here’s how it would look:

Address Value
1000 90
1001 AB
1002 12
1003 CD

Little Endian:

In little endian, you store the least significant byte in the smallest address. Here’s how it would look:

Address Value
1000 CD
1001 12
1002 AB
1003 90

Here is some code to determine what is the type of your machine

int num = 1;
if(*(char *)&num == 1)
{
printf("
Little-Endian
");
}
else
{
printf("Big-Endian
");
}

And here is some code to convert from one Endian to another.

int myreversefunc(int num)
{
int byte0, byte1, byte2, byte3;

byte0 = (num & x000000FF) >> 0 ;
byte1 = (num & x0000FF00) >> 8 ;
byte2 = (num & x00FF0000) >> 16 ;
byte3 = (num & xFF000000) >> 24 ;

return((byte0 << 24) | (byte1 << 16) | (byte2 << 8) | (byte3 << 0));
}