文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>两种很简单的判断系统是大端还是小端模式

两种很简单的判断系统是大端还是小端模式

时间:2010-09-03  来源:tianchunlong

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++= 用联合体来判断: #include<stdio.h>
union {         unsigned short a;         char b; }fan;
void main(void) {         fan.a=0x2211;         printf("fan.b=%x\n",fan.b); } ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ fan@fan:~/arm$ gcc -o app little.c  fan@fan:~/arm$ ./app fan.b=11//低位对应低地址,所以为小端 fan@fan:~/arm$  ====================================================================== +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 使用指针强转换 #include<stdio.h>
void main(void) {         unsigned short a;         a=0x2211;         printf("(char)a[0]=%x\n",((char*)&a)[0]);//注意他们的优先级         printf("(char)a[1]=%x\n",((char*)&a)[1]); } +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 运行结果: fan@fan:~/arm$ ./app (char)a[0]=11//和上面的结果一样,也是小端模式 (char)a[1]=22 fan@fan:~/arm$ 

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载