Skip to content

Instantly share code, notes, and snippets.

@liushooter
Forked from secretfader/hexlify_ruby.rb
Created March 5, 2019 07:32
Show Gist options
  • Select an option

  • Save liushooter/add0497d51762c7c3561efeeda0f985f to your computer and use it in GitHub Desktop.

Select an option

Save liushooter/add0497d51762c7c3561efeeda0f985f to your computer and use it in GitHub Desktop.
Hexlify in Ruby
def hexlify(msg)
msg.split("").collect { |c| c[0].to_s(16) }.join
end
def unhexlify(msg)
msg.scan(/../).collect { |c| c.to_i(16).chr }.join
end
puts hexlify("Hello World")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment