| C++ Builder 串口控件 | | C++ Builder 编程技巧 | | C++ Builder 操作指南 | | C++ Builder 参考手册 | | 基础知识 | | cfloat 浮点数 | | cmath 数学函数 | | cstdlib 标准库函数 | | • atof, _ttof, _wtof | | • _atold, _ttold, _wtold | | • atoi, _ttoi, _wtoi | | • atol, _ttol, _wtol | | • _atoi64, _ttoi64, _wtoi64 | | • strtod, _tcstod, wcstod | | • strtof, _tcstof, wcstof | | • strtold, _strtold, _tcstold, wcstold, _wcstold | | • strtol, _tcstol, wcstol | | • strtoll, _tcstoll, wcstoll | | • strtoul, _tcstoul, wcstoul | | • strtoull, _tcstoull, wcstoull | | • itoa, _itot, _itow | | • ltoa, _ltoa, _ltot, _ltow | | • ultoa, _ultot, _ultow | | • _i64toa, _i64tot, _i64tow | | • _ui64toa, _ui64tot, _ui64tow | | • ecvt, _ecvt | | • fcvt, _fcvt | | • gcvt, _gcvt | | • abs, labs, llabs | | • div, ldiv, lldiv | | • div_t, ldiv_t, lldiv_t | | • _rotl, _crotl, _lrotl | | • _rotr, _crotr, _lrotr | | • rand, _lrand | | • srand | | • random | | • randomize | | • mbstowcs | | • mblen | | • mbtowc | | • mbtowc_cp | | • wcstombs | | • wctomb | | • wctomb_cp | | • swab, _swab | | • _fullpath, _tfullpath, _wfullpath | | • _makepath, _tmakepath, _wmakepath | | • _splitpath, _tsplitpath, _wsplitpath | | • getenv, _tgetenv, _wgetenv | | • putenv, _putenv, _tputenv, _wputenv | | • _searchenv, _tsearchenv, _wsearchenv | | • _searchstr, _tsearchstr, _wsearchstr | | • system, _tsystem, _wsystem | | • abort | | • atexit | | • atexit_t | | • exit, _exit | | • abort_handler_s | | • ignore_handler_s | | • constraint_handler_t | | • set_constraint_handler_s | | • _argc | | • _argv, _targv, _wargv; | | • _environ, _tenviron, _wenviron | | • EXIT_SUCCESS, EXIT_FAILURE | | • _MAX_PATH, _MAX_DRIVE, _MAX_DIR, _MAX_FNAME, _MAX_EXT | | • MB_CUR_MAX | | • RAND_MAX, LRAND_MAX | | System 字符串 | | System 日期和时间 | | System.Math.hpp 数学函数 | | 其他数据类型 | | VCL 基础类 | | VCL 应用程序 | | Pictures 图片 | | Graphics 绘图 | | Additional 控件 | | System 控件 | | A ~ Z 字母顺序排列的目录 | | 网友留言/技术支持 |
|
| _rotr, _crotr, _lrotr - 循环右移 |
_rotr, _crotr, _lrotr:循环右移
函数原型:
| unsigned short _rotr(unsigned short value, int count); |
| unsigned char _crotr(unsigned char value, int count); |
| unsigned long _lrotr(unsigned long value, int count); |
头文件:
#include <cstdlib>
命名空间:
std
参数:
value:整数值,_rotr:16位无符号整数,_crotr:8位无符号整数,_lrotr:32位无符号整数
count:循环右移的位数
返回值:
value 循环右移 count 位的值
↘
↘
↘
例子:
void __fastcall TForm1::Button1Click(TObject *Sender)
{
unsigned short v = 0xC8A5; // 1100100010100101 原始数据:C8A5
int c = 3; // 1100100010100 → 101 从低位移出3位
unsigned short x = _rotr(v, c); // 101 → 1100100010100 从高位移入
// 1011100100010100 运算结果:B914
UnicodeString s;
s.sprintf(L"_rotr(0x%04X, 0x%04X) = 0x%04X", v, c, x);
Memo1->Lines->Add(s);
} |

兼容性:
由于 _rotr, _crotr, _lrotr 这一组函数不是标准 C/C++ 函数,从测试结果,即下面的表格来看,Embarcadero 已经抛弃这个函数了,
尽管 Visual C++ 也保留了这一组函数,但是 Embarcadero 不想在 C++ Builder 里面继续保留这一组函数了。
如果想在 64 位程序里面使用这一组函数,需要按照规则自己写,例如 _rotr(v, c) 可以用 (v>>c) | (v<<(16-c)) 实现。
相关链接:
• _rotl • div • abs
|
|
|
|