Find most significant bit (left-most) that is set in a bit array

Posted by Claudiu on Stack Overflow See other posts from Stack Overflow or by Claudiu
Published on 2010-04-06T23:42:59Z Indexed on 2010/04/06 23:53 UTC
Read the original article Hit count: 186

Filed under:
|
|

I have a bit array implementation where the 0th index is the MSB of the first byte in an array, the 8th index is the MSB of the second byte, etc...

What's a fast way to find the first bit that is set in this bit array? All the related solutions I have looked up find the first least significant bit, but I need the first most significant one. So, given 0x00A1, I want 9.

© Stack Overflow or respective owner

Related posts about bit-manipulation

Related posts about 32bit