Bloomberg interview question

-How would you write a program to detect processor endianness?

Interview Answer

Anonymous

Sep 20, 2010

Number = byte3 byte2 byte1 byte0 little endian - byte0 byte1 byte2 byte3 nig endian - byte3 byte2 byte1 byte0 unsigned int i = 1; char *p; if ( (*(char *)&i)) == 1) little endian else big endian