the ascii to binary and binary to ascii conversion is carried out by the in-built binascii module. it has a very straight forward usage with functions which take the input data and do the conversion. the below program shows the use of binascii module and its functions named b2a_uu and a2b_uu. the uu stands for "unix-to-unix encoding" which takes care of the data conversion from strings to binary and ascii values as required by the program.
import binascii text = "simply easy learning" # converting binary to ascii data_b2a = binascii.b2a_uu(text) print "**binary to ascii** \n" print data_b2a # converting back from ascii to binary data_a2b = binascii.a2b_uu(data_b2a) print "**ascii to binary** \n" print data_a2b
when we run the above program we get the following output −
**binary to ascii** 44vem&qy($5awd@3&5afyi;f **ascii to binary** simply easy learning