Skip to content

Instantly share code, notes, and snippets.

@antoni
Created July 9, 2015 20:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antoni/6b621d10fc738d4dec50 to your computer and use it in GitHub Desktop.
Save antoni/6b621d10fc738d4dec50 to your computer and use it in GitHub Desktop.
Detecting endianness at runtime
/*
* Source:
* http://stackoverflow.com/a/1001373/963881
*/
int is_big_endian(void)
{
union {
uint32_t i;
char c[4];
} bint = {0x01020304};
return bint.c[0] == 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment