From MSDN
Search the mask data from most significant bit (MSB) to least significant bit (LSB) for a set bit (1).
unsigned char _BitScanReverse
(
unsigned long * Index,
unsigned long Mask
);
Parameters
[out] Index
Loaded with the bit position of the first set bit (1) found.
[in] Mask
The 32-bit or 64-bit value to search.
Return Value
0 if the mask is zero; nonzero otherwise.
Remarks
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.
Please tell me how to implement a safe and fast _BitScanReverse() function on OS X? Do I have to use assembly or is there more simple way?
GCC has some similar built-ins:
If you have the number of zeros, you should be able to figure out where the first 1 is. 🙂