Created
October 9, 2012 12:51
-
-
Save giacomomacri/3858626 to your computer and use it in GitHub Desktop.
Convert from/to ASCII-8 bit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
my_string = "jackmacrack" | |
my_string_ascii = "" | |
my_string.each_char { |c| my_string_ascii += "#{c.ord}".rjust(3, '0') } #padding to 3 char, otherwise it's impossibile to reconvert | |
puts my_string_ascii # => 106097099107109097099114097099107 | |
my_original_string = "" | |
my_string_ascii.scan(/.../).each {|c| my_original_string += c.to_i.chr } | |
puts my_original_string # => jackmacrack |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment