逆向扫描指令

逆向扫描指令BSR(Bit Scan Reverse),从左向右扫描,即从高位向低位扫描。

Search the mask data from most significant bit (MSB) to least significant bit (LSB) for a set bit (1).

即第一个出现1的位置。

原型:unsigned char _BitScanReverse(unsigned long * Index, unsigned long Mask);

返回值:Nonzero if Index was set,or 0 if no set bits were found.

#include   
#include   
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;  
   }  
}

你可能感兴趣的:(C++)