Python – Binary ASCII Conversion


Python – Convert Binary to ASCII


”;


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

Advertisements

”;

Leave a Reply

Your email address will not be published. Required fields are marked *