Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 22 Aug 1999 01:01:57 -0700
From:      John-Mark Gurney <gurney_j@efn.org>
To:        Mark Murray <mark@grondar.za>
Cc:        Nick Hibma <hibma@skylink.it>, FreeBSD Hackers mailing list <hackers@FreeBSD.ORG>
Subject:   Re: from number to power of two
Message-ID:  <19990822010157.02195@hydrogen.fircrest.net>
In-Reply-To: <199908220750.JAA69064@gratis.grondar.za>; from Mark Murray on Sun, Aug 22, 1999 at 09:50:12AM %2B0200
References:  <199908220750.JAA69064@gratis.grondar.za>

next in thread | previous in thread | raw e-mail | index | archive | help
Mark Murray scribbled this message on Aug 22:
> > 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.

ummm, didn't you read his post?? he wanted a O(1) routine, NOT a O(n)
routine...

-- 
  John-Mark Gurney                              Voice: +1 541 684 8449
  Cu Networking					  P.O. Box 5693, 97405

  "The soul contains in itself the event that shall presently befall it.
  The event is only the actualizing of its thought." -- Ralph Waldo Emerson


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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?19990822010157.02195>