std::bit_reverse
From cppreference.com
| Defined in header <bit>
|
||
template< class T >
constexpr T bit_reverse( T x ) noexcept;
|
(since C++29) | |
Returns x with the order of the bits reversed.
Parameters
| x | - | a value whose bits to reverse |
| Type requirements | ||
| T | - | must be an unsigned integer type (that is, unsigned char, unsigned short, unsigned int, unsigned long, unsigned long long, or an extended unsigned integer type) in order to participate in overload resolution.
|
Return value
x with the order of the bits reversed.
Notes
The function is typically implemented using an intrinsic such as Clang's __builtin_bitreverse, and has the same effect as the rbit instruction on ARM CPUs.
| Feature-test macro | Value | Std | Feature |
|---|---|---|---|
__cpp_lib_bitops |
202607L |
(C++29) | Bit permutations |
Example
Run this code
#include <bit>
#include <cstdint>
static_assert(
std::bit_reverse(
std::uint8_t{0b1010'0011}) ==
std::uint8_t{0b1100'0101} and
std::bit_reverse(
std::uint16_t{0b1010'0011}) ==
std::uint16_t{0b1100'0101'0000'0000}
);
int main() {}
See also
(C++20) |
computes the result of bitwise left-rotation (function template) |
(C++20) |
computes the result of bitwise right-rotation (function template) |
(C++23) |
reverses the bytes in the given integer value (function template) |