Last active
April 25, 2018 08:20
-
-
Save alifarazz/2e0858d85a3b4b17396cc3844ba56860 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
#include <stdio.h> | |
#include <stdint.h> | |
union ConverterIntChar { | |
int i; | |
char c[4]; | |
}; | |
int main() | |
{ | |
int32_t a = 0x12345678; | |
union ConverterIntChar ctr; | |
#ifdef __BIG_ENDIAN__ | |
puts("Preproccessor says BIG endian"); | |
#elif __LITTLE_ENDIAN__ | |
puts("Preproccessor says LITTLE endian"); | |
#else | |
puts("Preproccessor says nothing :/"); | |
#endif | |
ctr.i = a; | |
printf("orig: 0x%08x\nbyte: 0x%02x::0x%02x::0x%02x::0x%02x\n" | |
, a, ctr.c[0], ctr.c[1], ctr.c[2], ctr.c[3]); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Oh thanks I have been looking for this