Write a simple program to test whether the "int "data type are stored as
big-endian or little-endian on a specific machine.
(Constraint :"pointer"type should not be used in the program if you use c/c++)
(Suppose a numeric data of type "int" data type use 4 bytes)好像很简单,可是我想了半天都觉得被什么卡住了,考官也说这道题很难,希望能被做出来的人给打动!

解决方案 »

  1.   

    big-endian little-endian 
    是什么意思?
      

  2.   

    不知大家有何看法?我觉得用一个union来判断一下就行了。
      

  3.   

    用union可以。
    int main()
    {   union
      {
        int a;
        short b[2];
       }kg;
        kg.a=0x00010002;
      if (kg.b[0]==1&&kg.b[1]==2)
        printf("big");
      else if(kg.b[0]==2&&kg.b[1]==1)
        printf("little");
      else
        printf("god knows!@#!@#");
    return 0;
    }
      

  4.   

    Write a simple program to test whether the "int "data type are stored as
    big-endian or little-endian on a specific machine.
    (Constraint :"pointer"type should not be used in the program if you use c/c++)
    (Suppose a numeric data of type "int" data type use 4 bytes)写一个简单的程序,测试一下在指定的机器上 “int”数据类型是用  big-endian 还是 little-endian 存储的条件:如果用 c/c++ 不能使用"pointer"
    假设:一个 int 类型为 4 个字节
    我的英语不好,不知我看得对不对,本题是什么意思?
    这个 big-endian 是什么意思? 大结尾?
    关注,
      

  5.   

    big-endian 就是通常所说的高端字节顺序,即在内存中,该整数的高字节在前(低位),如0x11223344,在内存中从第0到第3字节分别是0x11,0x22,0x33,0x44。little-endian反之。在网络通讯中,经常会遇到此类整数相互转换的问题(主机字节序和网络字节序互相转换)newhand2000() 的测试思路正确!