Python – Convert Binary to ASCII

Python – Converting Binary to ASCII

Binary-to-ASCII and ASCII-to-binary conversions are handled by the built-in binascii module. It has a very simple usage, using functions that accept input data and perform conversions. The following program demonstrates the use of the binascii module and its functions named b2a_uu and a2b_uu. “uu” stands for “Unix-to-Unix encoding” and is responsible for converting data from strings into 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

Leave a Reply

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