`
wss71104307
  • 浏览: 219106 次
  • 性别: Icon_minigender_1
  • 来自: 南京
社区版块
存档分类
最新评论

Big_endian and little_endian

阅读更多
试题1:请写一个C函数,若处理器是Big_endian的,则返回0;若是Little_endian的,则
返回1

Answer:
int checkCPU()
{
 {
  union w
  { 
   int a;
   char b;
  } c;
  c.a = 1;
  return (c.b == 1);
 }
}


定义一个union数据结构,里面a和b是使用同一个地址的,int是2Bytes,而b则是1
Byte的,也就是a的低8位(总共16位)。令a=1, 则在big endian机器上,a用16进制
表示为0x01,0x00(低地址), 此时b为它的低8位也就是0x00. little endian反之。
关于2个endian上网去查把。



分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics