hexlify and unhexlify

J

Jonas Galvez

Is there any built-in module that does this for me?

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("In Ruby...")
puts unhexlify("496e20527562792e2e2e")


--Jonas Galvez
 
N

nobuyoshi nakada

Hi,

At Wed, 29 Jun 2005 09:46:59 +0900,
Jonas Galvez wrote in [ruby-talk:146716]:
Is there any built-in module that does this for me?

def hexlify(msg) msg.unpack("H*")[0]
end
def unhexlify(msg) [msg].pack("H*")
end

puts hexlify("In Ruby...")
puts unhexlify("496e20527562792e2e2e")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top