_BitScanReverse、_BitScanReverse64

Microsoft 专用

从设置位 (1) 的最高有效位 (MSB) 到最低有效位 (LSB) 搜索掩码数据。

语法

unsigned char _BitScanReverse(
   unsigned long * Index,
   unsigned long Mask
);
unsigned char _BitScanReverse64(
   unsigned long * Index,
   unsigned __int64 Mask
);

参数

Index
[out] 加载已找到的第一个设置位 (1) 的数位位置。 其他情况下则不定义。

掩码
[in] 要搜索的 32 位或 64 位值。

返回值

如果 Mask 中设置了任何位,则为非零,如果未设置位,则为 0。

要求

Intrinsic 体系结构 Header
_BitScanReverse x86、ARM、x64、ARM64 <intrin.h>
_BitScanReverse64 ARM64、x64 <intrin.h>

示例

// 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

结束 Microsoft 专用

另请参阅

编译器内部函数