Created
October 30, 2016 18:27
-
-
Save Logrus/b5161428b3b9cf9f016f9901834de2d1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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