Little Endian - Big Endian Problem

后端 未结 7 542
你的背包
你的背包 2021-01-13 14:15

Little Endian vs Big Endian

Big Endian = 0x31014950
Little Endian = 0x50490131

However Using this Method

inline unsigned int endian         


        
7条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-13 14:35

    Bit operators are not useful because they operates as if the bits are arranged in order from least significant bit to most significant bit regardless of the true internal byte order.

    void isBigEndian()
    {
        void *number;
        number = (int *) new int(0x01000010);
        // 0x01000010
        //   01 00 00 10                                      Hexadecimal
        //   0    1      0    0      0    0       1    0
        //   0000 0001   0000 0000   0000 0000    0001 0000   Bit
        //   1           0           0            16          Decimal
        char *byte;
        byte = (char *)number;
        cout << static_cast(*byte);//prints 16: Little Endian
    }
    

    You change the number above and make it return 1 when it is BigEndian.

提交回复
热议问题