Skip to content

Instantly share code, notes, and snippets.

@nakal
Created October 31, 2015 22:26
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 nakal/92ddf81fbd828c873d94 to your computer and use it in GitHub Desktop.
Save nakal/92ddf81fbd828c873d94 to your computer and use it in GitHub Desktop.
Endianness test for C (untested)
#include <stdio.h>
int is_little_endian(void)
{
char buf[sizeof(unsigned int)];
*(unsigned int *)buf = 1u;
return (int)buf[0];
}
int main(void)
{
printf("This host is %s endian.\n",
is_little_endian() ? "little" : "big");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment