Skip to content

Instantly share code, notes, and snippets.

Created Oct 31, 2015
What would you like to do?
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