Module: Bite

Extended by:
Bite
Included in:
Bite
Defined in:
lib/bite.rb

Instance Method Summary collapse

Instance Method Details

#get_bits(bits, a) ⇒ Object



9
10
11
12
13
# File 'lib/bite.rb', line 9

def get_bits bits, a
  result = []
  bits.split("").each_with_index{|s, i| result << a[i] if s == '1'}
  return result
end

#toggle_bit(s, i) ⇒ Object



3
4
5
6
7
# File 'lib/bite.rb', line 3

def toggle_bit s, i
  t = s.split ""
  t[i] = ((t[i].to_i + 1) % 2).to_s
  t.join
end