Skip to content

Instantly share code, notes, and snippets.

@zhaoyao
Created October 27, 2012 15:47
Show Gist options
  • Save zhaoyao/3965128 to your computer and use it in GitHub Desktop.
Save zhaoyao/3965128 to your computer and use it in GitHub Desktop.
Endiness test
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;
}
@zhaoyao
Copy link
Author

zhaoyao commented Oct 27, 2012

@zhaoyao
Copy link
Author

zhaoyao commented Oct 27, 2012

memrevifle == mem_reverse_if_little_endian

@zhaoyao
Copy link
Author

zhaoyao commented Oct 27, 2012

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