John Joyce wrote:
>
> On Aug 16, 2007, at 3:22 PM, Stefano Crocco wrote:
>
>> Alle gioved? 16 agosto 2007, John Joyce ha scritto:
>>> On Aug 16, 2007, at 2:57 PM, Wolfgang N?dasi-Donner wrote:
>>>> John Joyce wrote:
>>>>> Hmm... I can turn a number into a character with .chr
>>>>> I can convert my numbers with .to_s(2)  ((where 2 is a radix, or
>>>>> base))
>>>>> But how do I convert numbers to characters??
>>>>
>>>> I don't understand what you mean - "to_s(b)" builds a string. What do
>>>> you mean by "convert numbers to characters" (example).
>>>>
>>>> Wolfgang N?dasi-Donner
>>>> -- 
>>>> Posted via http://www.ruby-forum.com/.
>>>
>>> yes it builds a string representation of a number.
>>> I want to take a hex or binary number though and return a character.
>>> 0x49 for example is "I"
>>
>> I think you need Integer#chr:
>>
>> 0x49.chr
>> => 'I'
>>
>> Stefano
>>
> Oops, no, that's not what I need. I can do that.
> I need to take "I" or "J" or whatever character and convert to hex! or 
> binary
> (sorry, I'm a little sleepy now)
>

Ah well in that case:

?I
# => 73

?I.to_s(2)
# => "1001001"

?I.to_s(16)
# => "49"

Tom Preston-Werner

-- 
* Libraries:
    Chronic (chronic.rubyforge.org)
    God (god.rubyforge.org)
* Site:
    rubyisawesome.com