_rotr8、_rotr16
[このドキュメントはプレビュー版であり、後のリリースで変更されることがあります。 Blank topics are included as placeholders.]
Microsoft 固有の仕様 →
ビット位置の指定した数の最下位ビットに (LSB) 入力値を右に回転します。
unsigned char _rotr8(
unsigned char value,
unsigned char shift
);
unsigned short _rotr16(
unsigned short value,
unsigned char shift
);
パラメーター
[入力] value
設定する値。[入力] shift
回転するビット数。
戻り値
回転後の値を返します。
必要条件
組み込み |
アーキテクチャ |
---|---|
_rotr8 |
x86IPFx64 |
_rotr16 |
x86IPFx64 |
ヘッダー ファイル <intrin.h>
解説
右シフト演算とは異なり右に回転を実行すると最低限のある下位ビットに上位ビットの場所に移動されます。
使用例
// rotr.cpp
#include <stdio.h>
#include <intrin.h>
#pragma intrinsic(_rotr8, _rotr16)
int main()
{
unsigned char c = 'A', c1, c2;
for (int i = 0; i < 8; i++)
{
printf_s("Rotating 0x%x right by %d bits gives 0x%x\n", c,
i, _rotr8(c, i));
}
unsigned short s = 0x12;
int nBit = 10;
printf_s("Rotating unsigned short 0x%x right by %d bits "
"gives 0x%x\n",
s, nBit, _rotr16(s, nBit));
}