Friday, June 18, 2010

Determine the endian'ess of the current platform

The following function would determine whether the current platform is little endian or not

bool is_little_endian()
{
unsigned short int word = 1;
unsigned short int mask = 0x00;

// get the most significant bytes of the word
unsigned short int msb = word>>4;

// the platform is little endian if the most significant bytes
// contains zero
if ( (msb | mask) == 0 )
{
return true;
}
return false;
}

No comments: