// This program uses pointers and pointer arithmetics in C to determine // if the program is running on a machine with a network byte ordering // (big endian) or intel byte ordering (little endian). #include int ordering() { unsigned int x = 1; return *((char*)&x+3); } int main() { if (ordering()) printf("network byte ordering\n"); else printf("intel byte ordering\n"); exit(0); } // function to switch the byte ordering of a 32bit integer: int switchorder(int x) { unsigned char A[4]; A[3] = *((unsigned char*)x); A[2] = *((unsigned char*)x+1); A[1] = *((unsigned char*)x+2); A[0] = *((unsigned char*)x+3); return *((int*)A); }