Skip to content

Instantly share code, notes, and snippets.

@Yoone
Created February 25, 2018 05:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Yoone/1c4b39fc19ee728d79cc3d5203f38d8c to your computer and use it in GitHub Desktop.
Save Yoone/1c4b39fc19ee728d79cc3d5203f38d8c to your computer and use it in GitHub Desktop.
Test endianness in C
#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