How do I convert between big-endian and little-endian values in C++?

前端 未结 30 2540
难免孤独
难免孤独 2020-11-21 23:18

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

30条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-22 00:02

    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.

提交回复
热议问题