Nix (Dev)
3.5.10
dev - 3.5.10 - 1af9301
Loading...
Searching...
No Matches
bswapOps.hpp
Go to the documentation of this file.
1
/*
2
* Byte Swapping Operations
3
*/
4
5
#ifndef IV_SRC_CORE_BYTESWAPOPS_HPP_
6
#define IV_SRC_CORE_BYTESWAPOPS_HPP_
7
8
#include <cstdint>
9
10
namespace
iv::bit
11
{
12
16
constexpr
uint16_t
reverseBytes
(
const
uint16_t x)
17
{
18
return
static_cast<
uint16_t
>
((x << 8) | (x >> 8));
19
}
20
27
constexpr
uint32_t
reverseBytes
(
const
uint32_t x)
28
{
29
// MSVC at least recognizes this as a bswap
30
return
((x & 0x000000FF) << 24) | ((x & 0x0000FF00) << 8) | ((x & 0x00FF0000) >> 8) | ((x & 0xFF000000) >> 24);
31
}
32
39
constexpr
uint64_t
reverseBytes
(
const
uint64_t x)
40
{
41
auto
hi =
static_cast<
uint32_t
>
(x >> 32);
42
auto
lo =
static_cast<
uint32_t
>
(x);
43
44
hi =
reverseBytes
(hi);
45
lo =
reverseBytes
(lo);
46
47
return
(
static_cast<
uint64_t
>
(lo) << 32) | hi;
48
}
49
50
}
// namespace iv::bit
51
52
#endif
iv::bit
Definition
bswapOps.hpp:11
iv::bit::reverseBytes
constexpr uint16_t reverseBytes(const uint16_t x)
Definition
bswapOps.hpp:16
src
core
bswapOps.hpp
Generated by
1.12.0