I want to take a value like:
ff0000
and make it into a byte array containing those hex values:
\xff\x00\x00
I'm not clear on how to do this using str.unpack
I want to take a value like:
ff0000
and make it into a byte array containing those hex values:
\xff\x00\x00
I'm not clear on how to do this using str.unpack
I'm not sure unpack can do this. Try this instead:
"ff0000".gsub(/../) { |match| match.hex.chr }
"ff0000".scan(/../).map { |match| match.hex } #=> [255, 0, 0]
or
("ff0000".scan(/../).map { |match| match.hex }).pack('C*') #=> "\377\000\000"
Depending on what format you want it in.