Created
February 25, 2018 05:14
-
-
Save Yoone/1c4b39fc19ee728d79cc3d5203f38d8c to your computer and use it in GitHub Desktop.
Test endianness in C
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
#include <stdio.h> | |
#include <stdint.h> | |
static inline uint8_t is_big_endian(void) | |
{ | |
const uint16_t endian = 256; | |
return *(const uint8_t *)&endian; | |
} | |
int main(void) | |
{ | |
if (is_big_endian()) | |
printf("Big endian\n"); | |
else | |
printf("Little endian\n"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment