From: Robert Klemme Date: 2009-01-13T16:24:15+09:00 Subject: Re: XOR two binary strings On 12.01.2009 20:52, Joel VanderWerf wrote: > Gary Chris wrote: >> Howdy, >> >> I am having difficulty finding how to XOR 2 binary strings. >> Is there a builtin function for this ? >> Something like >> return string_one ^ string_two >> >> Thanks > > All I can think of at the moment: > > a = [0b00000001, 0b00001000].pack("C*") > b = [0b10000001, 0b01000000].pack("C*") > > c = a.unpack("C*").zip(b.unpack("C*")) > c = c.map {|x,y| x^y} > c = c.pack("C*") > p c There's also irb(main):002:0> ("00000001".to_i(2) ^ "0110".to_i(2)).to_s(2) => "111" Kind regards robert -- remember.guy do |as, often| as.you_can - without end