Little Endian vs Big Endian
Big Endian = 0x31014950
Little Endian = 0x50490131
However Using this Method
inline unsigned int endian
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.