- #1
noblerare
- 50
- 0
Hi all,
I am wondering is there a way to count the number of bits to the left or right of a given 1 in a 32-bit integer?
For example, if I give the function the number 32 = 0b100000, there are 5 bits to the right of the 1 and hence, 26 bits to the left of the 1.
The catch is, is there a way to do this by simply using bit operations? i.e. no loops or conditionals? Bit operations include: & ^ | << >> ! and ~
Thanks
I am wondering is there a way to count the number of bits to the left or right of a given 1 in a 32-bit integer?
For example, if I give the function the number 32 = 0b100000, there are 5 bits to the right of the 1 and hence, 26 bits to the left of the 1.
The catch is, is there a way to do this by simply using bit operations? i.e. no loops or conditionals? Bit operations include: & ^ | << >> ! and ~
Thanks