_bitscanforward, _BITSCANFORWARD64

Source: Internet
Author: User

_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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.