Skip to content

Instantly share code, notes, and snippets.

@kapowaz
Created May 13, 2012 13:00
Show Gist options
  • Select an option

  • Save kapowaz/2688378 to your computer and use it in GitHub Desktop.

Select an option

Save kapowaz/2688378 to your computer and use it in GitHub Desktop.
Determine the next power of two above a given number
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