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;
}
Swapping variables without using temp
March 27, 2008
1) i = i + j ; j = i - j; i = i - j
2) i = i * j ; i = i / j; i = i / j
3) i = i ^ j; i = i ^ j; i = i ^ j