_bitscanforward (64) is used to include header files Intrin.h
unsigned char _bitscanforward ( unsigned long * Index, unsigned long Mask); unsigned char_bitscanforward64 ( unsigned long * Index, unsigned __int64 Mask);
The role of the _bitscanforward (64) function is to search for the most significant bit (most significant bit) in 2 binary form from the least significant bit of mask (least significant bit) until 1 is found.
eg.
unsigned long index0, index1, Index2;
unsigned long mask0 = 1 B;
unsinged long mask1 = 100B;
unsigned long mask2 = 1100B;
_bitscanforward (&index0, Mask0);
_bitscanforward (&index1, Mask1);
_bitscanforward (&index2, Mask2);
The resulting results are:
index0 = 0; Because 1 appears in the first place
Index1=index2 = 2;//100b and the first 1 of 1100B are present in the third place
Note: The count in programming starts at 0, so the result that appears in 3rd bit 1 is 2.
1#include <iostream>2#include <intrin.h>3 using namespacestd;4 5 #pragmaIntrinsic (_bitscanforward)6 7 intMain ()8 {9UnsignedLongMask =0x1000;TenUnsignedLongindex; OneUnsignedCharIsnonzero; A -cout <<"Enter a positive integer as the mask:"<<Flush; -CIN >>Mask; theIsnonzero = _bitscanforward (&index, mask); - if(Isnonzero) - { -cout <<"Mask:"<< Mask <<"Index:"<< Index <<Endl; + } - Else + { Acout <<"No set bits found. Mask is zero."<<Endl; at } - return 0; -}
_bitscanforward, _BITSCANFORWARD64