Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert numbers to alphabet? [duplicate]

Tags:

python

I read this thread about converting the alphabet to numbers but I don't understand how to convert the numbers back into letters. I would appreciate if someone could expand on that, especially and more specifically, the chr() function described in the thread. I've already tried searching for the chr function but there aren't many tutorials for it.

like image 419
user2734815 Avatar asked Aug 31 '13 04:08

user2734815


People also ask

How do you convert numbers into alphabets?

The Letter-to-Number Cipher (or Number-to-Letter Cipher or numbered alphabet) consists in replacing each letter by its position in the alphabet , for example A=1, B=2, Z=26, hence its over name A1Z26 .

How do I convert numbers to alphabets in Excel?

Type the formula =SpellNumber(A1) into the cell where you want to display a written number, where A1 is the cell containing the number you want to convert. You can also manually type the value like =SpellNumber(22.50). Press Enter to confirm the formula.

How do I convert numbers to words in Python?

num2words module in Python, which converts number (like 34) to words (like thirty-four). Also, this library has support for multiple languages. In this article, we will see how to convert number to words using num2words module. One can easily install num2words using pip.


1 Answers

If you have a number, for example 65, and if you want to get the corresponding ASCII character, you can use the chr function, like this

>>> chr(65)
'A'

similarly if you have 97,

>>> chr(97)
'a'

EDIT: The above solution works for 8 bit characters or ASCII characters. If you are dealing with unicode characters, you have to specify unicode value of the starting character of the alphabet to ord and the result has to be converted using unichr instead of chr.

>>> print unichr(ord(u'\u0B85'))
அ

>>> print unichr(1 + ord(u'\u0B85'))
ஆ

NOTE: The unicode characters used here are of the language called "Tamil", my first language. This is the unicode table for the same http://www.unicode.org/charts/PDF/U0B80.pdf

like image 150
thefourtheye Avatar answered Oct 06 '22 05:10

thefourtheye