Re: bit position
- From: Richard Heathfield <invalid@xxxxxxxxxxxxxxx>
- Date: Wed, 25 Oct 2006 17:22:06 +0000
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)
.
- References:
- bit position
- From: Serve Laurijssen
- bit position
- Prev by Date: Re: fclose then fopen equivalent for stdout?
- Next by Date: Re: fclose then fopen equivalent for stdout?
- Previous by thread: bit position
- Next by thread: Re: bit position
- Index(es):