Quick Links
Categories
Links
How to find the endianness∞ of a system?
Finding the byte order(byte-endianness):
Courtesy:
Alessandro's∞ post∞ in C community.
int nNumber = 1;
char cArray[ sizeof(int) ];
memcpy(cArray, &nNumber, sizeof(int));
if (cArray[ 0 ] == 0x01)
return IS_LITTLE_ENDIAN;
else
return IS_BIG_ENDIAN;
Note: This would be appropriate only for those systems which have either little or big endian. But if the system is middle-endian, this code would produce meaningless results.