Re: bit position



Serve Laurijssen said:

What would be an optimal way to get the position of the lowest bit where
you know only 1 bit will be on 1?

If you have an n-bit unsigned integer type, start off by comparing the value
with (1 << (n / 2)), and home in on the bit using binary search, for O(log
n) instead of O(n).

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
.