_rotl, _rotl64, _rotr, _rotr64

将位向左 (_rotl) 或向右 (_rotr) 旋转。

语法


unsigned int _rotl(
   unsigned int value,
   int shift
);
unsigned __int64 _rotl64(
   unsigned __int64 value,
   int shift
);
unsigned int _rotr(
   unsigned int value,
   int shift
);
unsigned __int64 _rotr64(
   unsigned __int64 value,
   int shift
);

参数

value
要旋转的值。

shift
要移动的位数。

返回值

旋转的值。 无错误返回。

备注

_rotl_rotr 函数按 shift 位旋转无符号 value_rotl 将值向左旋转。 _rotr 将值向右旋转。 两个函数将旋转的位从 value 的一端移到另一端。

要求

例程 必需的标头
_rotl_rotl64 <stdlib.h>
_rotr_rotr64 <stdlib.h>

有关兼容性的详细信息,请参阅 兼容性

C 运行时库的所有版本。

示例

// crt_rot.c
/* This program shifts values to rotate an integer.
*/

#include <stdlib.h>
#include <stdio.h>

int main( void )
{
   unsigned val = 0x0fd93;
   __int64 val2 = 0x0101010101010101;

   printf( "0x%4.4x rotated left three times is 0x%4.4x\n",
           val, _rotl( val, 3 ) );
   printf( "0x%4.4x rotated right four times is 0x%4.4x\n",
           val, _rotr( val, 4 ) );

   printf( "%I64x rotated left three times is %I64x\n",
           val2, _rotl64( val2, 3 ) );
   printf( "%I64x rotated right four times is %I64x\n",
           val2, _rotr64( val2, 4 ) );
}

输出

0xfd93 rotated left three times is 0x7ec98
0xfd93 rotated right four times is 0x30000fd9
101010101010101 rotated left three times is 808080808080808
101010101010101 rotated right four times is 1010101010101010

另请参阅

数学和浮点支持
_lrotl_lrotr