A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://en.cppreference.com/w/cpp/language/../numeric/rotl.html below:

std::rotl - cppreference.com

template< class T >
constexpr T rotl( T x, int s ) noexcept;

(since C++20)

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 r be s % N.

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).

[edit] Parameters x - value of unsigned integer type s - number of positions to shift [edit] Return value

The result of bitwise left-rotating x by s positions.

[edit] Notes [edit] Example
#include <bit>
#include <bitset>
#include <cstdint>
#include <iostream>
 
int main()
{
    using bin = std::bitset<8>;
    const std::uint8_t x{0b00011101};
    std::cout << bin(x) << " <- x\n";
    for (const int s : {0, 1, 4, 9, -1})
        std::cout << bin(std::rotl(x, s)) << " <- rotl(x, " << s << ")\n";
}

Output:

00011101 <- x
00011101 <- rotl(x, 0)
00111010 <- rotl(x, 1)
11010001 <- rotl(x, 4)
00111010 <- rotl(x, 9)
10001110 <- rotl(x, -1)
[edit] See also

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4