The binascii
is a widely used Python library for ASCII-encoded binary representations. It contains several methods for converting to binary from ASCII or hex, and vice versa.
We use binascii.b2a_hqx
for binary-to-ASCII translation in hexbin4 format. The method returns the resulting string. In order to use this function, we need to note a few things.
This function works in opposite to the
a2b_hqx()
method.
binascii.b2a_hqx(data)
This method returns a binary string.
Let’s work through a few coding examples using b2a_hqx
.
import binascii data = "Hello World" ## convert to binary text_bytes = bytes(data,'utf-8') ## perform b2a_hqx print(data, "==>", binascii.b2a_hqx(text_bytes)) data1 = "Welcome to educative" ## convert to binary text_bytes1 = bytes(data1,'utf-8') ## perform b2a_hqx print(data1, "==>", binascii.b2a_hqx(text_bytes1))
RELATED TAGS
CONTRIBUTOR
View all Courses