Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 22 Aug 1999 22:18:42 +0900
From:      Kazufumi-MIT-Mitani <mit@mit-s.otaru-uc.ac.jp>
To:        hackers@FreeBSD.ORG
Subject:   Re: from number to power of two
Message-ID:  <199908221318.WAA14821@mitss5.mit-s.otaru-uc.ac.jp>
In-Reply-To: Your message of "Sun, 22 Aug 1999 20:06:56 %2B0900"
References:  <37BFD9D0.D330B565@newsguy.com>

next in thread | previous in thread | raw e-mail | index | archive | help
 "Daniel C. Sobral" <dcs@newsguy.com> 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




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