_rotl8, _rotl16

Microsoft 专用

通过指定的位位置数将输入值旋转到最高有效位 (MSB) 左侧。

unsigned char _rotl8( 
   unsigned char value, 
   unsigned char shift 
);
unsigned short _rotl16( 
   unsigned short value, 
   unsigned char shift 
);

参数

  • [in] value
    要旋转的值。

  • [in] shift
    要旋转的位的数。

返回值

旋转的值。

要求

内部函数

体系结构

_rotl8

x86、ARM、x64

_rotl16

x86、ARM、x64

头文件 <intrin.h>

备注

不像左移操作,当执行向左旋转时,离开高端的高序位将移动到最低有效位位置。

示例

// rotl.cpp
#include <stdio.h>
#include <intrin.h>

#pragma intrinsic(_rotl8, _rotl16)

int main()
{
    unsigned char c = 'A', c1, c2;

    for (int i = 0; i < 8; i++)
    {
       printf_s("Rotating 0x%x left by %d bits gives 0x%x\n", c,
               i, _rotl8(c, i));
    }

    unsigned short s = 0x12;
    int nBit = 10;

    printf_s("Rotating unsigned short 0x%x left by %d bits gives 0x%x\n",
            s, nBit, _rotl16(s, nBit));
}
  

请参见

参考

_rotr8, _rotr16

编译器内部函数