How to check whether a system is big endian or little endian?
Another C code using union
union { int i; char c[sizeof(int)]; } x; x.i = 1; if(x.c[0] == 1) printf("little-endian\n"); else printf("big-endian\n");
It is same logic that belwood used.