_rotl8、_rotl16
[このドキュメントはプレビュー版であり、後のリリースで変更されることがあります。 Blank topics are included as placeholders.]
Microsoft 固有の仕様 →
ビット位置の指定した数の最上位ビットを (MSB) 左に入力値を回転します。
unsigned char _rotl8(
unsigned char value,
unsigned char shift
);
unsigned short _rotl16(
unsigned short value,
unsigned char shift
);
パラメーター
[入力] value
設定する値。[入力] shift
回転するビット数。
戻り値
回転後の値を返します。
必要条件
組み込み |
アーキテクチャ |
---|---|
_rotl8 |
x86IPFx64 |
_rotl16 |
x86IPFx64 |
ヘッダー ファイル <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));
}