Skip to content

Instantly share code, notes, and snippets.

@sdvcrx
Created August 8, 2013 03:14
Show Gist options
  • Save sdvcrx/6181143 to your computer and use it in GitHub Desktop.
Save sdvcrx/6181143 to your computer and use it in GitHub Desktop.
辨别系统是64位 or 32位以及大小端
#include <stdio.h>
int main(void)
{
int a = 0x80000000;
printf("os is %d\t%d\n", a, sizeof(int));
union ut {
short s;
char c[2];
} u;
if(sizeof(short) == 2){
u.s = 0x0102;
if (u.c[0] == 1 && u.c[1] == 2) {
printf("big endian.\n");
}
else if (u.c[0] == 2 && u.c[1] == 1) {
printf("little endian.\n");
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment