Class: String

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

Overview

extend String

Instance Method Summary collapse

Instance Method Details

#xor(other) ⇒ Object Also known as: ^

given two numeric strings, returns the bitwise xor string



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/abiparser.rb', line 12

def xor(other)
    a = self.bytes
    b = other.bytes
    ## todo/check: cut-off on lower count (lc) - why? why not?
    lc = (a.size < b.size) ? a.size : b.size
    c = []
    lc.times do |i|
       c << (a[i] ^ b[i])
    end
    c = c.pack( 'C*' )
    puts "#{self.bin_to_hex} ^ #{other.bin_to_hex} = #{c.bin_to_hex}<"
    c
end