Forum: Ruby Ascii Character to Decimal Base 10 value

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
E700f28e33f22aa356f21833cfd7cba4?d=identicon&s=25 Doug Meharry (doug3)
on 2006-05-12 01:47
Greetings all,

I would like to know how one might convert a letter such as "H" to its
corresponding ascii decimal value.  On the flip side, how might I take
the decimal value and convert it back to the alpha-numeric
representation.

Is there something simpler or better than using the String class
each_byte() method?  I seem to recall there is a simple way to do just
this, but can't find it in the docs.

Thanks,

Doug

PS: any ideas about doing this with Unicodes?
Bbc4b3fca1ae3161257a8636145b424d?d=identicon&s=25 Elliot Temple (Guest)
on 2006-05-12 02:13
(Received via mailing list)
irb(main):124:0> 99.chr
=> "c"



On May 11, 2006, at 4:47 PM, doug meharry wrote:

>
> Thanks,
>
> Doug
>
> PS: any ideas about doing this with Unicodes?
>
> --
> Posted via http://www.ruby-forum.com/.
>
>

-- Elliot Temple
http://www.curi.us/blog/
Bbc4b3fca1ae3161257a8636145b424d?d=identicon&s=25 Elliot Temple (Guest)
on 2006-05-12 02:16
(Received via mailing list)
irb(main):132:0> "H"[0]
=> 72

On May 11, 2006, at 4:47 PM, doug meharry wrote:

>
> Thanks,
>
> Doug
>
> PS: any ideas about doing this with Unicodes?
>
> --
> Posted via http://www.ruby-forum.com/.
>
>

-- Elliot Temple
http://www.curi.us/blog/
12271b6df73fe29930d65586be5a4a70?d=identicon&s=25 Dave Howell (Guest)
on 2006-05-12 02:16
(Received via mailing list)
On May 11, 2006, at 16:47, doug meharry wrote:

> Greetings all,
>
> I would like to know how one might convert a letter such as "H" to its
> corresponding ascii decimal value.  On the flip side, how might I take
> the decimal value and convert it back to the alpha-numeric
> representation.
>
> Is there something simpler or better than using the String class
> each_byte() method?  I seem to recall there is a simple way to do just
> this, but can't find it in the docs.

It's (to me) wildly non-intuitive.

 > aString = 'B'
=> "B"
 > aString[0]
=> 66
 > aString[0..0]
=> "B"
E34b5cae57e0dd170114dba444e37852?d=identicon&s=25 Logan Capaldo (Guest)
on 2006-05-12 02:41
(Received via mailing list)
On May 11, 2006, at 7:47 PM, doug meharry wrote:

>
> Thanks,
>
> Doug
>
> PS: any ideas about doing this with Unicodes?
>
> --
> Posted via http://www.ruby-forum.com/.
>

?H #=> 72
?H.chr #=> "H"
E700f28e33f22aa356f21833cfd7cba4?d=identicon&s=25 Doug Meharry (doug3)
on 2006-05-12 03:46
Logan Capaldo wrote:
> On May 11, 2006, at 7:47 PM, doug meharry wrote:
>
>>
>> Thanks,
>>
>> Doug
>>
>> PS: any ideas about doing this with Unicodes?
>>
>> --
>> Posted via http://www.ruby-forum.com/.
>>
>
> ?H #=> 72
> ?H.chr #=> "H"

Thanks all, that works well.
This topic is locked and can not be replied to.