Skip to content

Latest commit

 

History

History
124 lines (105 loc) · 2.5 KB

bitscanreverse-bitscanreverse64.md

File metadata and controls

124 lines (105 loc) · 2.5 KB
title _BitScanReverse, _BitScanReverse64 | Microsoft Docs
ms.custom
ms.date 11/04/2016
ms.reviewer
ms.suite
ms.technology
cpp-tools
ms.tgt_pltfrm
ms.topic article
f1_keywords
_BitScanReverse64
_BitScanReverse_cpp
_BitScanReverse
_BitScanReverse64_cpp
dev_langs
C++
helpviewer_keywords
bsr instruction
_BitScanReverse intrinsic
BitScanReverse intrinsic
ms.assetid 2520a207-af8b-4aad-9ae7-831abeadf376
caps.latest.revision 12
author corob-msft
ms.author corob
manager ghogen
translation.priority.ht
cs-cz
de-de
es-es
fr-fr
it-it
ja-jp
ko-kr
pl-pl
pt-br
ru-ru
tr-tr
zh-cn
zh-tw

_BitScanReverse, _BitScanReverse64

Microsoft Specific

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

Syntax

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

Parameters

[out] Index
Loaded with the bit position of the first set bit (1) found.

[in] Mask
The 32-bit or 64-bit value to search.

Return Value

Nonzero if Index was set, or 0 if no set bits were found.

Requirements

Intrinsic Architecture Header
_BitScanReverse x86, ARM, [!INCLUDEvcprx64] <intrin.h>
_BitScanReverse64 ARM, [!INCLUDEvcprx64]

Example

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

Input

12  

Sample Output

Enter a positive integer as the mask:   
Mask: 12 Index: 3  

END Microsoft Specific

See Also

Compiler Intrinsics