Spec-Zone.ru › C++

std::bit_reverse

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, unsignedchar, unsignedshort, unsignedint, unsignedlong, unsignedlonglong, 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 202607L (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

rotl
(C++20)
computes the result of bitwise left-rotation
(function template)
rotr
(C++20)
computes the result of bitwise right-rotation
(function template)
byteswap
(C++23)
reverses the bytes in the given integer value
(function template)

© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/cpp/numeric/bit_reverse

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API