分享方式:


_BitScanReverse, _BitScanReverse64

Microsoft 特定的

從遮罩資料的最高有效位元 (MSB) 到最低有效位元 (LSB) 搜尋設定位元 (1)。

語法

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。

需求

內建 架構 標題
_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

END Microsoft 特定的

另請參閱

編譯器內建函式