Created
May 13, 2012 13:00
-
-
Save kapowaz/2688378 to your computer and use it in GitHub Desktop.
Determine the next power of two above a given number
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def next_power_two(number) | |
| number.to_s(2).split("").inject("") {|s, c| s+= "1" }.to_i(2) + 1 | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment