編寫程序判斷程序、數據大小端存儲方式

大小端這個問題在面試過程中偶爾會被問到,這裏筆者總結了一

 

int CheckSystemDataFormat(void)
{
    int i = 0x0a12780b;
    char *c = &i;
    return ((c[0] == 0x0a) && (c[1] == 0x12) && (c[2] == 0x78) && (c[3] == 0x0b));
}

int main(void)
{	
    if(CheckSystemDataFormat())		
    printf("little endian\n");	
    else		
    printf("big endian\n");	
    return 0;
}

 

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章