Converting Big-Endian network byte order to Little-Endian host byte order in Modern C++:
Before C++23, developers used compiler-specific intrinsics (_byteswap_ulong in MSVC or __builtin_bswap32 in GCC).
In C++23, std::byteswap is a standard, constexpr function in <bit>:
#include <bit>
uint32_t netPacketLength = 0x12345678;
uint32_t hostLength = std::byteswap(netPacketLength); // Evaluates to 0x78563412Compiles directly to the native bswap x86 CPU instruction or REV on ARM!