Skip to content

Instantly share code, notes, and snippets.

@alifarazz
Last active April 25, 2018 08:20
Show Gist options
  • Save alifarazz/2e0858d85a3b4b17396cc3844ba56860 to your computer and use it in GitHub Desktop.
Save alifarazz/2e0858d85a3b4b17396cc3844ba56860 to your computer and use it in GitHub Desktop.
#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;
}
@sinabr
Copy link

sinabr commented Apr 25, 2018

Oh thanks I have been looking for this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment