Skip to content

Instantly share code, notes, and snippets.

@khajavi
Last active December 17, 2015 19:39
Show Gist options
  • Save khajavi/5662524 to your computer and use it in GitHub Desktop.
Save khajavi/5662524 to your computer and use it in GitHub Desktop.
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
int main() {
union
{
uint8_t c[4];
uint32_t i;
} u;
u.i = 0x01020304;
if (0x04 == u.c[0])
printf("Little endian\n");
else if (0x01 == u.c[0])
printf("Big endian\n");
int num = 1;
if(*(char *)&num == 1) {
printf("\nLittle-Endian\n");
} else {
printf("Big-Endian\n");
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment