bitops.h
int _inline_bsf(unsigned v); int _inline_bsr(unsigned v);
_inline_bsr scans the bits in v from the most significant bit to the least significant bit, looking for the first set bit.
These functions are inlined by the compiler, bringing to bear the full power of the code generator on them. This can result in some surprising speedups when they are used as part of a bit array solution.
Return Value
Both return the bit number of the first set bit.
The return value is undefined if v is zero.
Compatibility
DOS, Windows 3.x, Phar Lap, DOSX, Win32
See Also
_inline_bt,
_inline_btc,
_inline_bts,
_inline_btr
Example
#include <stdio.h>
#include <bitops.h>
int main()
{
unsigned v;
int x;
v = 0x21;
x = _inline_bsf(v);
printf("bsf(x%x) = %d\n", v, x);
x = _inline_bsr(v);
printf("bsr(x%x) = %d\n", v, x);
return 0;
}
Outputbsf(x21) = 0 bsr(x21) = 5