From owner-freebsd-hackers Sun Aug 22 6:19:13 1999 Delivered-To: freebsd-hackers@freebsd.org Received: from mitss5.mit-s.otaru-uc.ac.jp (mitss5.mit-s.otaru-uc.ac.jp [150.83.68.42]) by hub.freebsd.org (Postfix) with ESMTP id 2CECA14D01 for ; Sun, 22 Aug 1999 06:19:06 -0700 (PDT) (envelope-from mit@mitss5.mit-s.otaru-uc.ac.jp) Received: (from mit@localhost) by mitss5.mit-s.otaru-uc.ac.jp (8.7.5+2.6Wbeta6/3.4W4-mit-s) id WAA14821; Sun, 22 Aug 1999 22:18:42 +0900 (JST) Message-Id: <199908221318.WAA14821@mitss5.mit-s.otaru-uc.ac.jp> To: hackers@FreeBSD.ORG Subject: Re: from number to power of two From: Kazufumi-MIT-Mitani Reply-To: mit@mit-s.otaru-uc.ac.jp In-Reply-To: Your message of "Sun, 22 Aug 1999 20:06:56 +0900" References: <37BFD9D0.D330B565@newsguy.com> X-Mailer: Mew version 1.06 on Emacs 19.28.1, Mule 2.3 Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Date: Sun, 22 Aug 1999 22:18:42 +0900 Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG "Daniel C. Sobral" wrote > That technique is O(ln(n)), where n is the number in question. > > Frankly, for numbers up to 32, a table will wield the best results, > and might actually be smaller than some of the suggestions given so > far. Counting n as bit, it is O(n) :p Unrolling the loop, if(n<=2^0) 2^0 else if(n<=2^1) 2^1 else if(n<=2^2) 2^2 else if(n<=2^3) 2^3 : : else if(n<=2^31) 2^31 is suitable for this problem? --- //mit To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message