Skip to content

Instantly share code, notes, and snippets.

@meklu
Created February 26, 2016 20:20
Show Gist options
  • Save meklu/16441cb50b0197dad653 to your computer and use it in GitHub Desktop.
Save meklu/16441cb50b0197dad653 to your computer and use it in GitHub Desktop.
#include <stdio.h>
int main(void) {
int a = 0xdeadbeef;
/* Always big-endian */
printf("%c%c%c%c\n", (a & 0xff000000) >> 24, (a & 0xff0000) >> 16, (a & 0xff00) >> 8, (a & 0xff));
/* Native endian */
printf("%c%c%c%c\n", ((char*) &a)[0], ((char*) &a)[1], ((char*) &a)[2], ((char*) &a)[3]);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment