#include <stdio.h>
int checkEndian(){
int p = 0xffff0000;
if(*(char*)&p==0xff) //char* pointer of p's first byte
printf("Big Endian");
else
printf("Little Endian"); //my pc is little endian
return 0;
}
int main(){
checkEndian();
}
Appendix
If the value of integer variable (32 bits) is0xffff0000 and your system is in big endian, it will be stored as binary in memory like:
low addr: 1111 1111
| 1111 1111
↓ 0000 0000
high addr: 0000 0000
No comments:
Post a Comment