How do I go about swapping bytes (little endian -> big endian and visa-versa) in a platform independent way.
I saw this:
However apparently there are some situations where it causes problems:Code:float FloatSwap( float f )
{
union
{
float f;
unsigned char b[4];
} dat1, dat2;
dat1.f = f;
dat2.b[0] = dat1.b[3];
dat2.b[1] = dat1.b[2];
dat2.b[2] = dat1.b[1];
dat2.b[3] = dat1.b[0];
return dat2.f;
}
double swap(double) Doesn't Work
I cant seem to get the correct values from the above function anyway. The dat2.f returned is always 0.0
Many Thanks,
-Alex