`
qvb3d
  • 浏览: 171179 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

检查你的机器是大端格式还是小端格式的C程序

 
阅读更多

检查你的机器是大端格式还是小端格式的C程序

 

#include <stdio.h>

union check

   {

      int high;

      char low;

   } test_ok;

int main(int argc,char *argv[])

{

   short test=0x0110;

   char *p=(char *)&test;

   if(p[0]==0x10)

   {

      //sm format

      printf("This arch is small format bits\n");

   }

   else

   {

      //big format 

      printf("This arch is big  format bits\n");

   }

   printf("point address1=0x%.4x address2=0x%.4x\n",p[0],p[1]);

   test_ok.high=1;

   if(test_ok.low==1)

    {

     printf("Arch is small format\n");

    }

   else

   {

      printf("Arch is big format\n");

   }

   return 0;

}


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics