I have a string containing byte data.
How can I perform an in-place conversion to ascii string?
You can do so via using base64 which is a fairly universal way.
require 'base64'
str = Base64.encode64(data)
if u have a binary string lets say something like:
s = "01001101011011110111000101110101011001010110010101110100"
and u wanna convert it back to ascii text in Ruby u can do like:
s = "01001101011011110111000101110101011001010110010101110100"
(0..s.length-8).step(8) do |i|
print s[i,8].to_i(base=2).chr
end
Hope this will help someone :)
Another way to play with binary data is String#unpack.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With