Export (0) Print
Expand All
Expand Minimize

_BitScanForward, _BitScanForward64

Microsoft Specific


unsigned char _BitScanForward(
   unsigned long * Index,
   unsigned long Mask
unsigned char_BitScanForward64(
   unsigned long * Index,
   unsigned __int64 Mask


[out] Index


[in] Mask

The 32-bit or 64-bit value to search.

0 if the mask is zero; nonzero otherwise.

If a set bit is found, the bit position of the first set bit found is returned in the first parameter. If no set bit is found, 0 is returned; otherwise, 1 is returned.

Intrinsic Architecture


x86, IPF, x64


IPF, x64

Header file <intrin.h>

// BitScanForward.cpp
// compile with: /EHsc
#include <iostream>
#include <intrin.h>
using namespace std;

#pragma intrinsic(_BitScanForward)

int main()
   unsigned long mask = 0x1000;
   unsigned long index;
   unsigned char isNonzero;
   cin >> mask;
   isNonzero = _BitScanForward(&index, mask);
   if (isNonzero)


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

END Microsoft Specific

Community Additions

© 2014 Microsoft