From: hadley wickham Date: 2006-08-07T23:47:26+09:00 Subject: Re: nextPowerOf2(n) > Can someone tell me if there's a better way to do this? It takes a > number and returns the next power of 2 up (or the original if it was > already a power of 2) Specifically, are there features of Ruby that I > should be using in this case? Try this: def log2(x) Math.log(x) / Math.log(2) end def nextPowerOf2(x) 2 ** (log2(x).ceil) end Hadley