ChrisDanson
Programmer
Hi,
I'm after a really efficient way of calculating n, given that the nth bit only is set in a bitmask. I have a 24bit mask with 1 bit set in it (it could be any bit). I can think of long winded ways to do it like bitshifting 1 to the left until a bitwise And returns true, but that is not efficient enough for my purposes. I'm going to go and read about the log function as I'm wondering if that will help. I guess a look up table would be ok for small masks but not for ones this big.
Can anyone shed light?
Thanks in advance.
Chris
I'm after a really efficient way of calculating n, given that the nth bit only is set in a bitmask. I have a 24bit mask with 1 bit set in it (it could be any bit). I can think of long winded ways to do it like bitshifting 1 to the left until a bitwise And returns true, but that is not efficient enough for my purposes. I'm going to go and read about the log function as I'm wondering if that will help. I guess a look up table would be ok for small masks but not for ones this big.
Can anyone shed light?
Thanks in advance.
Chris