How do I convert between big-endian and little-endian values in C++?
EDIT: For clarity, I have to translate binary data (double-precision floating point values and 3
There is an assembly instruction called BSWAP that will do the swap for you, extremely fast. You can read about it here.
Visual Studio, or more precisely the Visual C++ runtime library, has platform intrinsics for this, called _byteswap_ushort(), _byteswap_ulong(), and _byteswap_int64()
. Similar should exist for other platforms, but I'm not aware of what they would be called.