|
|
(C++20) | ||||
(C++23) | ||||
Integral powers of2 | ||||
(C++20) | ||||
(C++20) | ||||
(C++20) | ||||
(C++20) | ||||
Rotating | ||||
rotl (C++20) | ||||
(C++20) | ||||
Counting | ||||
(C++20) | ||||
(C++20) | ||||
(C++20) | ||||
(C++20) | ||||
(C++20) | ||||
Endian | ||||
(C++20) |
Defined in header <bit> | ||
template<class T> constexpr T rotl( T x,int s)noexcept; | (since C++20) | |
Computes the result of bitwise left-rotating the value ofx bys positions. This operation is also known as a leftcircular shift.
Formally, letN
bestd::numeric_limits<T>::digits andr bes% N.
This overload participates in overload resolution only ifT
is an unsigned integer type (that is,unsignedchar,unsignedshort,unsignedint,unsignedlong,unsignedlonglong, or an extended unsigned integer type).
Contents |
x | - | value of unsigned integer type |
s | - | number of positions to shift |
The result of bitwise left-rotatingx bys positions.
Feature-test macro | Value | Std | Feature |
---|---|---|---|
__cpp_lib_bitops | 201907L | (C++20) | Bit operations |
#include <bit>#include <bitset>#include <cstdint>#include <iostream> int main(){using bin=std::bitset<8>;conststd::uint8_t x{0b00011101};std::cout<< bin(x)<<" <- x\n";for(constint s:{0,1,4,9,-1})std::cout<< bin(std::rotl(x, s))<<" <- rotl(x, "<< s<<")\n";}
Output:
00011101 <- x00011101 <- rotl(x, 0)00111010 <- rotl(x, 1)11010001 <- rotl(x, 4)00111010 <- rotl(x, 9)10001110 <- rotl(x, -1)
(C++20) | computes the result of bitwise right-rotation (function template)[edit] |
performs binary shift left and shift right (public member function of std::bitset<N> )[edit] |