Skip to content

Instantly share code, notes, and snippets.

@lingling2012
Created April 25, 2013 02:52
Show Gist options
  • Save lingling2012/5457180 to your computer and use it in GitHub Desktop.
Save lingling2012/5457180 to your computer and use it in GitHub Desktop.
check little or big endian.
#include <stdio.h>
int checkEndian(void) {
union {
int i;
char ch;
}c;
c.i = 1;
return (c.ch == 1);
}
int main(int argc, char *argv[]) {
int rs;
rs = checkEndian();
if (rs == 1) {
printf("little endian");
} else {
printf("big endian");
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment