[Tutor] convert binary to ascii
Danny Yoo
dyoo at hkn.eecs.berkeley.edu
Fri Sep 2 19:48:28 CEST 2005
On Fri, 2 Sep 2005, Servando Garcia wrote:
> Here is my question : sam in binary is 01110011 01100001 01101101.
> if given 01110011 01100001 01101101 how would I go back to ascii.
Hi Servando:
If we have strings of ones and zeros, we can turn those into numbers by
using the int() function. For example:
######
>>> int("101", 2)
5
>>> int("110", 2)
6
>>> int("111", 2)
7
######
For more information on int(), see:
http://www.python.org/doc/lib/built-in-funcs.html#l2h-39
There is also a function to convert ordinals back into their ascii
character values. Take a look at:
http://www.python.org/doc/lib/built-in-funcs.html
and search for the word "ASCII": you should see a function there that will
help.
More information about the Tutor
mailing list