Hi I'm confused by the example code given here to check if a machine is little or big endian开发者_如何学编程:
Little Endian or Big Endian?
int isLittleEndian( void )
{
unsigned int temp = 0x12345678;
char * tempAddress = &temp;
if( *tempAddress == 0x12 )
{
return 0; // Indicating False
} else {
return 1; // Indicating True
}
}
Versus this description of little and big endianness given here:
http://support.microsoft.com/kb/102025
The second link says on an LE machine 0x1234 is stored in memory as 0x34 0x12, however the isLittleEndian() function in the first link is returning true if the first byte is 0x12. Isn't that a contradiction of the 2nd link? If not then what is it I've misunderstood?
No, the function returns false if the first byte is 0x12. Which is as it should be, and jives with the description of endianness.
精彩评论