利用union判断大端序和小端序
#include "stdafx.h"
#if 0
12 78
34 56
56 34
78 12
小端序 大端序
int data = 0x12345678;
if (*(char*)&data == 0x78)//以char* 类型访问
printf("小端序\n");
else
printf("大端序\n");
#endif
union test
{
int i;
char c;
};
int _tmain(int argc, _TCHAR* argv[])
{
union test t;
t.i = 0x12345678;
if (t.c == 0x78) //取地址取的为低字节地址
printf("小端序\n");
else
printf("大端序\n");
return 0;
}