Created
August 8, 2013 03:14
-
-
Save sdvcrx/6181143 to your computer and use it in GitHub Desktop.
辨别系统是64位 or 32位以及大小端
This file contains hidden or 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> | |
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