Skip to content

Instantly share code, notes, and snippets.

@marcinwyszynski
Created January 12, 2012 01:09
Show Gist options
  • Save marcinwyszynski/1597834 to your computer and use it in GitHub Desktop.
Save marcinwyszynski/1597834 to your computer and use it in GitHub Desktop.
Checking if an integer is a power of 2
Integer::class_eval do
def power_of_2?() (self & (self - 1)) == 0 end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment