Little Endian - Big Endian Problem

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

    If I run the code you posted, it gives the correct result: endian_swap ( 0x31014950 ) == 0x50490131.

    To get the result: endian_swap ( 0x31014950 ) == 0x54110131, your code must be equivalent to this:

    #define __
    inline unsigned int endian_swap(unsigned int& x)  
    {                  //0x31014950  ->            0x54110131
        return  ( ( (x & 0x000000FF) << 24 ) |   //  50
            __    ( (x & 0x00F0F000) << 12 ) |   //   4
            __    ( (x & 0x00FF0000) << 4  ) |   //    1  
            __    ( (x & 0x00FF0000) << 0  ) |   //     1  
            __    ( (x & 0x00FF0000) >> 8  ) |   //      01
            __    ( (x & 0xFF000000) >> 24 ) );  //        31        
    }
    

    Check you haven't got similar differences in your code too.

    0 讨论(0)
提交回复
热议问题