From: Umm Whyshouldisay Date: 2010-07-23T06:49:18+09:00 Subject: Re: Text to Binary Ammar Ali wrote: > On Thu, Jul 22, 2010 at 6:03 AM, Umm Whyshouldisay > wrote: >> No, what I mean is, I'm trying to translate text to ternary. So, I want >> to check EACH AND EVERY individual character and, depending on ASCII >> values, turn the characters into the number in ternary that represents >> that ASCII value. So, for example, in hex, an ! mark is 21. In decimal, >> that's 33. In ternary, that's 001020. I would keep going on in this >> manner and translate every single character into its respective ASCII >> number (in ternary). > > To avoid solving people's homework, only hints are usually given. > String#unpack is the way. Hint: look at the C and c format specifiers. > Another hint, Array#map. > If you share some code that shows that you've tried to solve it, it > makes it easier for others to take the time and help. > > HTH, > Ammar Alright, I think I'm almost there. I've got this: test = "Hello World!" test2 = test.unpack('c*') test3 = test2.collect {|x| x.to_s(3) + ' '} puts test3.to_s However, I want each number to have 6 digits (6 trits in a tryte). How would I do that? I want it to, if it didn't already have 6 digits in it, add the appropriate number of zeros in the beginning of it. Anyone got any suggestions here? -- Posted via http://www.ruby-forum.com/.