(no title)
peripetylabs | 12 years ago
http://en.wikipedia.org/wiki/Power_of_two#Fast_algorithm_to_...
(Edit: You forgot to subtract one before setting the lower bits and incrementing. If you omit that step, both these algorithms give the same result.)
Actually this algorithm is faster for smaller numbers too, because it always performs less operations in the loop -- one shift as opposed to a shift and a bitwise or.
ColinWright|12 years ago