Convert string with hex ASCII codes to characters Convert string with hex ASCII codes to characters ruby ruby

Convert string with hex ASCII codes to characters


You can use Array#pack:

["666f6f626172"].pack('H*')#=> "foobar"

H is the directive for a hex string (high nibble first).


Stefan has nailed it, but here's an alternative you may want to tuck away for another time and place:

"666f6f626172".gsub(/../) { |pair| pair.hex.chr } # => "foobar"