Unpacking String#UNPACK in Ruby!!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
l = "i am what i am" | |
# to integer | |
l.unpack('U*') # => [105, 32, 97, 109, 32, 119, 104, 97, 116, 32, 105, 32, 97, 109] | |
# to hex | |
l.unpack('H*') # => ["6920616d2077686174206920616d"] | |
# if you want the hex in array form then | |
l.unpack('U*').map{|i| i.to_s(16)} # => ["69", "20", "61", "6d", "20", "77", "68", "61", "74", "20", "69", "20", "61", "6d"] |