确定字节序

版权声明: https://blog.csdn.net/dashoumeixi/article/details/84774782

小端: 左->右

大端: 右->左

   union{
       short n;
       char c[sizeof(short)];
   }un;
   un.n = 0x0102;
   if(un.c[0] == 1 && un.c[1] == 2)
       puts("big");
   else if(un.c[0] = 2 && un.c[1] == 1)
       puts("little");
   else
       puts("unknow");

猜你喜欢

转载自blog.csdn.net/dashoumeixi/article/details/84774782