Friday, December 9, 2011

Write a program to find whether a machine is big endian or little endian.

1     #define BIG_ENDIAN 0
2     #define LITTLE_ENDIAN 1
3     int TestByteOrder() {
4             short int word = 0x0001;
5             char *byte = (char *) &word;
6             return (byte[0] ? LITTLE_ENDIAN : BIG_ENDIAN);
7     }

No comments:

Post a Comment