Converting float values from big endian to little endian

c++, endianness

Solution

simply reverse the four bytes works

float ReverseFloat( const float inFloat )
{
   float retVal;
   char *floatToConvert = ( char* ) & inFloat;
   char *returnFloat = ( char* ) & retVal;

   // swap the bytes into a temporary buffer
   returnFloat[0] = floatToConvert[3];
   returnFloat[1] = floatToConvert[2];
   returnFloat[2] = floatToConvert[1];
   returnFloat[3] = floatToConvert[0];

   return retVal;
}

Problem

Is it possible to convert `float`s from big to little endian? I have a big endian value from a PowerPC platform that I am sendING via TCP to a Windows process (little endian). This value is a `float`, but when I `memcpy` the value into a Win32 float type and then call `_byteswap_ulong`on that value, I always get 0.0000? What am I doing wrong?

Original source

Related problems