tags:

views:

1577

answers:

2

I have a string containing byte data.
How can I perform an in-place conversion to ascii string?

+1  A: 

You can do so via using base64 which is a fairly universal way.

require 'base64'

str = Base64.encode64(data)
Phil
data needs to be convertible to String for this to work. Try, for example:irb(main):002:0> Base64.encode64(1234)TypeError: can't convert Fixnum into String
Brent.Longborough
+4  A: 

Another way to play with binary data is String#unpack.

Keltia
Thanks - unpack('H*') did the job.
LK