From owner-freebsd-hackers Sun Aug 22 1: 2:29 1999 Delivered-To: freebsd-hackers@freebsd.org Received: from metriclient-1.uoregon.edu (metriclient-1.uoregon.edu [128.223.172.1]) by hub.freebsd.org (Postfix) with ESMTP id A0D691539C for ; Sun, 22 Aug 1999 01:02:13 -0700 (PDT) (envelope-from gurney_j@efn.org) Received: (from jmg@localhost) by metriclient-1.uoregon.edu (8.9.1/8.8.7) id BAA07432; Sun, 22 Aug 1999 01:01:57 -0700 (PDT) Message-ID: <19990822010157.02195@hydrogen.fircrest.net> Date: Sun, 22 Aug 1999 01:01:57 -0700 From: John-Mark Gurney To: Mark Murray Cc: Nick Hibma , FreeBSD Hackers mailing list Subject: Re: from number to power of two References: <199908220750.JAA69064@gratis.grondar.za> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 0.69 In-Reply-To: <199908220750.JAA69064@gratis.grondar.za>; from Mark Murray on Sun, Aug 22, 1999 at 09:50:12AM +0200 Reply-To: John-Mark Gurney Organization: Cu Networking X-Operating-System: FreeBSD 3.0-RELEASE i386 X-PGP-Fingerprint: B7 EC EF F8 AE ED A7 31 96 7A 22 B3 D8 56 36 F4 X-Files: The truth is out there X-URL: http://resnet.uoregon.edu/~gurney_j/ Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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