Class: Integer
- Inherits:
-
Object
- Object
- Integer
- Defined in:
- lib/core/integer.rb
Instance Method Summary collapse
-
#bits ⇒ Object
FIXME: consider right-shifting self and counting ones.
- #log2_ceil ⇒ Object
Instance Method Details
#bits ⇒ Object
FIXME: consider right-shifting self and counting ones
4 5 6 |
# File 'lib/core/integer.rb', line 4 def bits (0...to_s(2).size).select { |bit| self[bit] == 1 } end |
#log2_ceil ⇒ Object
8 9 10 11 |
# File 'lib/core/integer.rb', line 8 def log2_ceil return 0 if self == 0 or self == 1 (self - 1).to_s(2).size end |