[python]ASCII to integer and vice versa

There are two functions in python which can convert the ascii to the integer equivalent and vice versa.
To convert ascii character to integer representation use ord(), to convert integer to ascii representation use chr().


plaintext = "hello world!"
ascii_to_num = [ord(pt) for pt in plaintext]
num_to_ascii = ''.join(chr(an) for an in ascii_to_num)


[104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100, 33]
hello world!


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s