Check Big/Little Endian

Little endian:Low memory address stores low byte value.(eg.  short int 0x2211   0xbfd05c0e->0x11 | 0xbfd05c0f->0x22)

Big endian:Low memory address stores high byte value. (eg.  short int 0x2211   0xbfd05c0e->0x22 | 0xbfd05c0f->0x11)

 

#include <endian.h>



bool IsLittleEndian1()



{



    return BYTE_ORDER == LITTLE_ENDIAN ? true : false;



}







bool IsLittleEndian2()



{



    short endian = 0x2211;







    return *((char*)(&endian)) == 0x11 ? true : false;



}

 

你可能感兴趣的:(check)