Class: Integer

Inherits:
Object
  • Object
show all
Defined in:
lib/core/integer.rb

Instance Method Summary collapse

Instance Method Details

#bitsObject

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_ceilObject



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