Endianness

July 12, 2008

Big-Endian: MSB has the lowest address (Motoroal processors, SPARC)

Little-endian: LSB has the lowest address (x86, VAX, Z80, 6502)

+ Networks generally use big-endian order
+ English language uses big-endian order

Algorithms to determine the endianness of a machine:

//Return 0 if little-endian; 1 if big-endian
int Endianess1()
{
     int testNum = 1;
     char *ptr = (char*)&testNum;

return *ptr; //return the first byte
}

int Endianness2()
{
      union {
           int theInterger;
           char singleByte;
       } endianTest;

       endianTest.theInteger = 1;
       return endianTest.singleByte;
}

Leave a Reply