Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python:Ascii character<->decimal representation conversion

Tags:

Hi I need to be able to convert a ascii character into its decimal equivalent and vice-versa.

How can I do that?

like image 812
Alpagut Avatar asked Dec 08 '10 11:12

Alpagut


2 Answers

num=ord(char)
char=chr(num)

For example,

>>> ord('a')
97
>>> chr(98)
'b'

You can read more about the built-in functions in Python here.

like image 112
Adam Matan Avatar answered Oct 01 '22 06:10

Adam Matan


Use ord to convert a character into an integer, and chr for vice-versa.

like image 25
Karl Knechtel Avatar answered Oct 01 '22 06:10

Karl Knechtel