Created
October 7, 2016 09:49
-
-
Save RklAlx/a46b1d67696124de1287efeb18b79eb7 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
// https://helloacm.com/how-to-find-out-whether-a-machine-is-big-endian-or-little-endian-in-cc/ | |
#include <stdio.h> | |
#define BIG_ENDIAN 0 | |
#define LITTLE_ENDIAN 1 | |
int TestByteOrder() { | |
short int word = 0x0001; | |
char *b = (char *)&word; | |
return (b[0] ? LITTLE_ENDIAN : BIG_ENDIAN); | |
} | |
int main() { | |
int r = TestByteOrder(); | |
printf("%s\n", r == LITTLE_ENDIAN ? "Little Endian" : "Big Endian"); | |
return r; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment