Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::rotr

      From cppreference.com
      <cpp‎ |numeric
       
       
      Utilities library
       
       
      Defined in header<bit>
      template<class T>
      constexpr T rotr( T x,int s)noexcept;
      (since C++20)

      Computes the result of bitwise right-rotating the value ofx bys positions. This operation is also known as a rightcircular shift.

      Formally, letN bestd::numeric_limits<T>::digits andr bes% N.

      • Ifr is0, returnsx;
      • ifr is positive, returns(x>> r)|(x<<(N- r));
      • ifr is negative, returnsstd::rotl(x,-r).

      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

      [edit]Parameters

      x - value of unsigned integer type
      s - number of positions to shift

      [edit]Return value

      The result of bitwise right-rotatingx bys positions.

      [edit]Notes

      Feature-test macroValueStdFeature
      __cpp_lib_bitops201907L(C++20)Bit operations

      [edit]Example

      Run this code
      #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,9,-1,2})std::cout<< bin(std::rotr(x, s))<<" <- rotr(x, "<< s<<")\n";}

      Output:

      00011101 <- x00011101 <- rotr(x, 0)10001110 <- rotr(x, 1)10001110 <- rotr(x, 9)00111010 <- rotr(x, -1)01000111 <- rotr(x, 2)

      [edit]See also

      (C++20)
      computes the result of bitwise left-rotation
      (function template)[edit]
      performs binary shift left and shift right
      (public member function ofstd::bitset<N>)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/numeric/rotr&oldid=182061"

      [8]ページ先頭

      ©2009-2025 Movatter.jp