# Ascii Character to Decimal Base 10 value

**URL:** <https://www.ruby-forum.com/t/ascii-character-to-decimal-base-10-value/60319>\
**Category:** Ruby\
**Created:** [May 12, 2006, 1:47am UTC](https://www.ruby-forum.com/t/ascii-character-to-decimal-base-10-value/60319 "2006-05-12T01:47:16Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![doug3](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b3f665/32.png) [@doug3](https://www.ruby-forum.com/u/doug3)\
**Post date:** [May 12, 2006, 1:47am UTC](https://www.ruby-forum.com/t/ascii-character-to-decimal-base-10-value/60319/1 "2006-05-12T01:47:16Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![doug3](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b3f665/32.png) [@doug3](https://www.ruby-forum.com/u/doug3)\
**Post date:** [May 12, 2006, 2:13am UTC](https://www.ruby-forum.com/t/ascii-character-to-decimal-base-10-value/60319/2 "2006-05-12T02:13:37Z")

</div>

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/](http://www.ruby-forum.com/).

– Elliot T.

> **[Curiosity Blog – Elliot Temple](https://www.curi.us/blog/)**
>
> A philosophy blog

---

<div class="post-metadata">

**Author:** ![doug3](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b3f665/32.png) [@doug3](https://www.ruby-forum.com/u/doug3)\
**Post date:** [May 12, 2006, 2:16am UTC](https://www.ruby-forum.com/t/ascii-character-to-decimal-base-10-value/60319/3 "2006-05-12T02:16:44Z")

</div>

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/](http://www.ruby-forum.com/).

– Elliot T.

> **[Curiosity Blog – Elliot Temple](https://www.curi.us/blog/)**
>
> A philosophy blog

---

<div class="post-metadata">

**Author:** ![doug3](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b3f665/32.png) [@doug3](https://www.ruby-forum.com/u/doug3)\
**Post date:** [May 12, 2006, 2:16am UTC](https://www.ruby-forum.com/t/ascii-character-to-decimal-base-10-value/60319/4 "2006-05-12T02:16:45Z")

</div>

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”

---

<div class="post-metadata">

**Author:** ![doug3](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b3f665/32.png) [@doug3](https://www.ruby-forum.com/u/doug3)\
**Post date:** [May 12, 2006, 3:46am UTC](https://www.ruby-forum.com/t/ascii-character-to-decimal-base-10-value/60319/5 "2006-05-12T03:46:37Z")

</div>

Logan C. 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/](http://www.ruby-forum.com/).
> 
> ?H #=\> 72  
> ?H.chr #=\> “H”

Thanks all, that works well.

---

<div class="post-metadata">

**Author:** ![doug3](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b3f665/32.png) [@doug3](https://www.ruby-forum.com/u/doug3)\
**Post date:** [May 12, 2006, 2:41am UTC](https://www.ruby-forum.com/t/ascii-character-to-decimal-base-10-value/60319/6 "2006-05-12T02:41:07Z")

</div>

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/](http://www.ruby-forum.com/).

?H #=\> 72  
?H.chr #=\> “H”
