You didn’t specifically ask the question, but you may need the output line to be the same as the input lines, using fill leading zeros . So, relying on steenslag slick answer (and adjusting the input values to illustrate a potential problem):
a = "14ef" b = "1ca3" (a.hex ^ b.hex).to_s(16) # "84c" (a.hex ^ b.hex).to_s(16).rjust(a.length, '0') # "084c"
Jeff ward
source share