Created
October 27, 2012 15:47
-
-
Save zhaoyao/3965128 to your computer and use it in GitHub Desktop.
Endiness test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int | |
is_big_endian() | |
{ | |
int test = 1; | |
unsigned char *testp = (unsigned char*) &test; | |
// test if the high bits is on the left | |
return testp[0] == 0; | |
} |
Many protocol use big endian (network endian), so when we implements a protocol in a little endian environment, we need to swap the high, low bits area.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
memrevifle == mem_reverse_if_little_endian