[bit.rotate]

# 22 General utilities library [[utilities]](./#utilities)

## 22.11 Bit manipulation [[bit]](bit#rotate)

### 22.11.6 Rotating [bit.rotate]

[1](#1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L15872)

In the following descriptions,
let N denote numeric_limits<T>​::​digits[.](#1.sentence-1)

[ð](#itemdecl:1)

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

[2](#2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L15883)

*Constraints*: T is an unsigned integer type ([[basic.fundamental]](basic.fundamental "6.9.2 Fundamental types"))[.](#2.sentence-1)

[3](#3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L15887)

Let r be s % N[.](#3.sentence-1)

[4](#4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L15890)

*Returns*: If r is 0, x;
if r is positive, (x << r) | (x >> (N - r));
if r is negative, rotr(x, -r)[.](#4.sentence-1)

[ð](#itemdecl:2)

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

[5](#5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L15904)

*Constraints*: T is an unsigned integer type ([[basic.fundamental]](basic.fundamental "6.9.2 Fundamental types"))[.](#5.sentence-1)

[6](#6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L15908)

Let r be s % N[.](#6.sentence-1)

[7](#7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L15911)

*Returns*: If r is 0, x;
if r is positive, (x >> r) | (x << (N - r));
if r is negative, rotl(x, -r)[.](#7.sentence-1)
