Little Endian - Big Endian Problem

后端 未结 7 548
你的背包
你的背包 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:30

    Have you unit-tested your code?

    On my platform, this passes:

    void LittleEndianTest::testLittleEndian()
    {
        unsigned int x = 0x31014950;
        unsigned int result = 
             (
                 ( (x & 0x000000FF) << 24 ) + 
                 ( (x & 0x0000FF00) << 8  ) +
                 ( (x & 0x00FF0000) >> 8  ) +
                 ( (x & 0xFF000000) >> 24 ) 
             );
    
        CPPUNIT_ASSERT_EQUAL((unsigned int)0x50490131, result); 
    }
    

提交回复
热议问题