std::rotl(3)
πΈ NAME πΈ
okay bestie, welcome to std::rotl from the C++ Standard Libary manual β yes, thatβs the manual name, typo and all ππ
. this page is std::rotl(3).
std::rotlβstd::rotl
β¨ Synopsis β¨
Defined in header <bit>.
template< class T > (since C++20)
[[nodiscard]] constexpr T rotl( T x, int s ) noexcept;
okay so what does it do? it computes the result of bitwise left-rotating the value of x by s positions. this operation is also known as a left circular shift πβ¨.
formally, let N be std::numeric_limits<T>::digits, and let r be s % N.
- If
ris0, returnsx; - if
ris positive, returns(x << r) | (x >> (N - r)); - if
ris negative, returnsstd::rotr(x, -r).
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). no sneaky signed types, bestie π«π.
π Parameters π
xβ value of unsigned integer typesβ number of positions to shift
π¦ Return value π¦
the result of bitwise left-rotating x by s positions. periodt π
π Notes π
feature-test macro vibe check:
- Feature-test macro:
__cpp_lib_bitopsβ value:201907L, std:(C++20), feature: Bit operations
π Example π
// Run this code
#include <bit>
#include <bitset>
#include <cstdint>
#include <iostream>
int main()
{
const std::uint8_t i = 0b00011101;
std::cout << "i = " << std::bitset<8>(i) << '\n';
std::cout << "rotl(i,0) = " << std::bitset<8>(std::rotl(i, 0)) << '\n';
std::cout << "rotl(i,1) = " << std::bitset<8>(std::rotl(i, 1)) << '\n';
std::cout << "rotl(i,4) = " << std::bitset<8>(std::rotl(i, 4)) << '\n';
std::cout << "rotl(i,9) = " << std::bitset<8>(std::rotl(i, 9)) << '\n';
std::cout << "rotl(i,-1) = " << std::bitset<8>(std::rotl(i, -1)) << '\n';
}
Output:
i = 00011101
rotl(i,0) = 00011101
rotl(i,1) = 00111010
rotl(i,4) = 11010001
rotl(i,9) = 00111010
rotl(i,-1) = 10001110
π See also π
rotrβ computes the result of bitwise right-rotation(C++20)(function template)operator<<=operator>>=β performs binary shift left and shift rightoperator<<β (public member function ofstd::bitset<N>)operator>>
byeee bestie π«Άπ this page is from <http://cppreference.com>, dated 2024.06.10 β std::rotl(3), muah πβ¨
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms