Can't you just swap them?
inline unsigned long long EndianChange( double d ) { char ch[8]; memcpy( ch, &d, 8 );
Edit: as indicated, the bytes are replaced with a double βcanβ is loaded into the register, so getting it back from this register may mean that the value is no longer valid, so keep it in a long, 64-bit one to avoid this problem.
This is all related to the byte. I'm not sure what you are trying to do, but every large platform I have ever used uses the same encoding as little-endian, only the byte order is reversed. The above code will change the byte order for you. Almost any compiler simply performs byte swapping, and then returns the byte byte variable and gets rid of memcpys. This is a good way to deal with alias problems.
source share