std::bit_reverse - cppreference.com
From cppreference.com
| Defined in header |
||
template< class T > constexpr T bit_reverse( T x ) noexcept; |
(since C++29) | |
Returns x with the order of the bits reversed.
This overload participates in overload resolution only if T is an unsigned integer type (that is, unsigned char, unsigned short, unsigned int, unsigned long, unsigned long long, or an extended unsigned integer type).
Parameters
| x | - | value of unsigned integer type |
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 |
202606L |
(C++29) | Bit permutations |
Example
#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
| computes the result of bitwise left-rotation (function template) [edit] | |
| computes the result of bitwise right-rotation (function template) [edit] | |
| reverses the bytes in the given integer value (function template) [edit] |