C / C++ FAQs & Programming Resources - ProkutFAQ : FindEndian

HomePage Recent Changes Recently Commented Login/Register

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.



There is one comment on this page. [Display comment]

Page was generated in 0.0509 seconds