Last active
December 17, 2015 19:39
-
-
Save khajavi/5662524 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 <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