Class: Integer

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

Instance Method Summary collapse

Instance Method Details

#hi_bitsObject



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/bx.rb', line 5

def hi_bits
  int = self
  Enumerator.new do |e|
    loop do
      b_len = int.bit_length
      break if b_len == 0
      pos = b_len - 1
      e << pos
      int = int ^ (1 << pos)
    end
  end
end

#lo_bitsObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/bx.rb', line 18

def lo_bits
  int = self
  Enumerator.new do |e|
    off = 0
    loop do
      lowest = int & -int
      break if lowest == 0
      b_len = lowest.bit_length
      off += b_len
      e << off - 1
      int = int >> b_len
    end
  end
end