_rotl, _crotl, _lrotl:循环左移
unsigned short _rotl(unsigned short value, int count);
unsigned char _crotl(unsigned char value, int count);
unsigned long _lrotl(unsigned long value, int count);
#include
std
value:整数值,_rotl:16位无符号整数,_crotl:8位无符号整数,_lrotl:32位无符号整数
count:循环左移的位数
value 循环左移 count 位的值
╭─
─ 高位移出低位移入 ─
─╮
╰←
1
1
0
1
0
1
0
1
←╯
↙
╭─
─ 高位移出低位移入 ─
─╮
╰←
1
0
1
0
1
0
1
1
←╯
↙
╭─
─ 高位移出低位移入 ─
─╮
╰←
0
1
0
1
0
1
1
1
←╯
↙
╭─
─ 高位移出低位移入 ─
─╮
╰←
1
0
1
0
1
1
1
0
←╯
void __fastcall TForm1::Button1Click(TObject *Sender)
{
unsigned short v = 0xC8A5; // 1100100010100101 原始数据:C8A5
int c = 3; // 110 ← 0100010100101 从高位移出3位
unsigned short x = _rotl(v, c); // 0100010100101 ← 110 从低位移入
// 0100010100101110 运算结果:452E
UnicodeString s;
s.sprintf(L"_rotl(0x%04X, 0x%04X) = 0x%04X", v, c, x);
Memo1->Lines->Add(s);
}
由于 _rotl, _crotl, _lrotl 这一组函数不是标准 C/C++ 函数,从测试结果,即下面的表格来看,Embarcadero 已经抛弃这个函数了,
尽管 Visual C++ 也保留了这一组函数,但是 Embarcadero 不想在 C++ Builder 里面继续保留这一组函数了。
如果想在 64 位程序里面使用这一组函数,需要按照规则自己写,例如 _rotl(v, c) 可以用 (v<>(16-c)) 实现。
bcc32
clang32
clang64
_rotl
√
√
_crotl
√
√
_lrotl
√
√