◐ Shell
reader mode source ↗
From cppreference.com
 
 
Utilities library
General utilities
Relational operators (deprecated in C++20)
Integer comparison functions
(C++20)(C++20)(C++20)    
(C++20)
Swap and type operations
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
Common vocabulary types
(C++11)
(C++17)
(C++17)
(C++17)
(C++11)
(C++17)
(C++23)



 
 
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.

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

(C++20)
computes the result of bitwise left-rotation
(function template) [edit]
(C++20)
computes the result of bitwise right-rotation
(function template) [edit]
(C++23)
reverses the bytes in the given integer value
(function template) [edit]