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;

}

 

posted @ 2014-11-21 09:32  stanley19861028  阅读(153)  评论(0编辑  收藏  举报