It seems that all the solutions are too generic and slow. As I only have
to check the numbers 0-32 (actually 1-32), a block of if statements is
almost as fast as a table look up in 33 elements.

Cheers,

Nick


On Sun, 22 Aug 1999, Mark Murray wrote:

> > Does anyone know an inexpensive algorithm (O(1)) to go from an number to
> > the next (lower or higher) power of two.
> > 
> > 1                   -> 1
> > 2,3                 -> 2
> > 4,5,6,7                     -> 4
> > 8,9,10,11,12,13,14,15       -> 8
> > etc.
> > 
> > So %1101 should become either %10000 or %1000.
> 
> Shift a bit until it becomes greater than (or less than) the number
> in question.
> 
> M
> --
> Mark Murray
> Join the anti-SPAM movement: http://www.cauce.org
> 
> 

-- 
e-Mail: hi...@skylink.it



To Unsubscribe: send mail to majord...@freebsd.org
with "unsubscribe freebsd-hackers" in the body of the message

Reply via email to