Skip to content

Instantly share code, notes, and snippets.

@hindenbug
Created May 7, 2011 21:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hindenbug/960847 to your computer and use it in GitHub Desktop.
Save hindenbug/960847 to your computer and use it in GitHub Desktop.
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"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment