Convert a string of 0-F into a byte array in Ruby
For a string str
:
"".tap {|binary| str.scan(/../) {|hn| binary << hn.to_i(16).chr}}
To get Integer — just str.hex
. You may get byte array in several ways:
str.scan(/../).map(&:hex)
[str].pack('H*').unpack('C*')
[str].pack('H*').bytes.to_a
See other options for pack/unpack
here: http://ruby-doc.org/core/classes/String.html#method-i-unpack
And examples here: http://www.codeweblog.com/ruby-string-pack-unpack-detailed-usage/