_BitScanReverse, _BitScanReverse64
Microsoft 전용
MSB(최상위 비트)에서 LSB(최하위 비트)로의 마스크 데이터에서 설정 비트(1)를 검색합니다.
unsigned char _BitScanReverse( unsigned long * Index, unsigned long Mask ); unsigned char _BitScanReverse64( unsigned long * Index, unsigned __int64 Mask );
매개 변수
[out] Index
발견된 첫 번째 설정 비트(1)의 비트 위치를 사용하여 로드됩니다.[in] Mask
검색할 32비트 또는 64비트 값입니다.
반환 값
Index가 설정된 경우에는 0이 아니고 설정 비트가 발견되지 않은 경우에는 0입니다.
요구 사항
내장 함수 |
아키텍처 |
Header |
---|---|---|
_BitScanReverse |
x86, ARM, x64 |
<intrin.h> |
_BitScanReverse64 |
ARM, x64 |
예제
// 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;
}
}
입력
12
샘플 출력
Enter a positive integer as the mask:
Mask: 12 Index: 3