MCPcopy Create free account
hub / github.com/andreasfertig/programming-with-cpp20 / ByteSwap

Function ByteSwap

10.03-byteSwap0/main.cpp:21–29  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

19}
20
21constexpr auto ByteSwap(std::integral auto value)
22{
23 if constexpr((std::endian::native == std::endian::big) ||
24 (sizeof(value) == 1)) { // #B chars don't need swapping
25 return value;
26 } else {
27 return ReverseBytes(value);
28 }
29}
30
31static_assert(ByteSwap(uint64_t(0x123456789ABCDEF0)) == 0xF0DEBC9A78563412);
32static_assert(ByteSwap(uint32_t(0x12345678)) == 0x78563412);

Callers 1

main.cppFile · 0.70

Calls 1

ReverseBytesFunction · 0.70

Tested by

no test coverage detected