Created
January 14, 2011 10:47
-
-
Save skorfmann/779465 to your computer and use it in GitHub Desktop.
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 is_a_power_of_two?(n) | |
| return false if n.is_a?(Float) | |
| (n-1)& n == 0 if n != 0 | |
| end | |
| def logb2(n) | |
| if is_a_power_of_two?(n) | |
| return n.to_s(2).match(/1(0*)/)[1].length | |
| else | |
| false | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment