Skip to content

Instantly share code, notes, and snippets.

@Logrus
Created October 30, 2016 18:27
Show Gist options
  • Save Logrus/b5161428b3b9cf9f016f9901834de2d1 to your computer and use it in GitHub Desktop.
Save Logrus/b5161428b3b9cf9f016f9901834de2d1 to your computer and use it in GitHub Desktop.
// Source: http://stackoverflow.com/questions/12791864/c-program-to-check-little-vs-big-endian
#include <stdio.h>
int main()
{
int x = 1;
char *y = (char*)&x;
if(*y){
printf("This computer is LITTLE endian.\n");
printf(" higher memory \n");
printf(" -----> \n");
printf(" +----+----+----+----+ \n");
printf(" |0x01|0x00|0x00|0x00| \n");
printf(" +----+----+----+----+ \n");
printf(" A \n");
printf(" | \n");
printf(" &x \n");
} else {
printf("This computer is BIG endian. \n");
printf(" +----+----+----+----+ \n");
printf(" |0x00|0x00|0x00|0x01| \n");
printf(" +----+----+----+----+ \n");
printf(" A \n");
printf(" | \n");
printf(" &x \n");
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment