Little Endian vs Big Endian
Big Endian = 0x31014950
Little Endian = 0x50490131
However Using this Method
inline unsigned int endian_swap(unsigned int& x)
{
return ( ( (x & 0x000000FF) << 24 ) |
( (x & 0x0000FF00) << 8 ) |
( (x & 0x00FF0000) >> 8 ) |
( (x & 0xFF000000) >> 24 ) );
}
result = 0x54110131
i spent lot of time trying lots of similar methods and even a library one like
unsigned long _byteswap_ulong(unsigned long value);
But Still no luck .. all returns same result
EDIT
I'm Working on Little-Endian System with Microsoft Visual Studio 2008
the example as Follows
int main()
{
unsigned int y = 0x31014950;
unsigned int r = endian_swap( y );
std::cout << r;
}
the example posted on Ideone.com is correct .. but it doesn't work with me
EDIT
std::cout << std::hex << r;
Either Ways Pals .. Hex or Not it's not getting the Right Number .. Either Visual Studio got a serious Error in it's Debugger or My Whole Machine ..
Because i Replaced the Whole Code with a More Slow Redunant code but still getting same results
BTW if it makes any difference .. i'm using Debugger to Break after the function to check the result
x
by reference, you never actually modify it. – James McNellisy
. The value you print out isy
. The output of this program surely is "822167888". If you print outr
, you'll see the endian-reversed value. – Steve Jessopcout << hex
, otherwise we get decimal output – Vlady
! Why would you think that your function,endian_swap
, modifiesy
in any way? It doesn't. – Steve Jessop