Created
January 12, 2012 01:09
-
-
Save marcinwyszynski/1597834 to your computer and use it in GitHub Desktop.
Checking if an integer is a power of 2
This file contains 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
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