_BitScanReverse, _BitScanReverse64
Microsoft 专用
从设置位 (1) 的最高有效位 (MSB) 到最低有效位 (LSB) 搜索掩码数据。
unsigned char _BitScanReverse( unsigned long * Index, unsigned long Mask ); unsigned char _BitScanReverse64( unsigned long * Index, unsigned __int64 Mask );
参数
[out] Index
已使用找到的第一个设置位 (1) 的位位置加载。[in] Mask
要搜索的 32 位或 64 位值。
返回值
如果设定 Index,则为非零,如果未发现设置位,则为 0。
要求
内部函数 |
体系结构 |
Header |
---|---|---|
_BitScanReverse |
x86、ARM、x64 |
<intrin.h> |
_BitScanReverse64 |
ARM、x64 |
示例
// BitScanReverse.cpp
// compile with: /EHsc
#include <iostream>
#include <intrin.h>
using namespace std;
#pragma intrinsic(_BitScanReverse)
int main()
{
unsigned long mask = 0x1000;
unsigned long index;
unsigned char isNonzero;
cout << "Enter a positive integer as the mask: " << flush;
cin >> mask;
isNonzero = _BitScanReverse(&index, mask);
if (isNonzero)
{
cout << "Mask: " << mask << " Index: " << index << endl;
}
else
{
cout << "No set bits found. Mask is zero." << endl;
}
}
输入
12
示例输出
Enter a positive integer as the mask:
Mask: 12 Index: 3