Q: Trying to understand binary conversion script I have the following python code, which converts a binary string into plain-text:
import bin ascii
n = int('01100001011000100110001101100100', 2)
binascii.unhexlify('%x' % n)

This code functions properly, but I don't understand what's going on here.


*

*What is the purpose of the "2" at the end of the int declaration?

*What is the purpose of the "'%x' % n" argument?


A: 
What is the purpose of the 2 at the end of the int declaration?

According to the documentation, int can take a second argument: the base of the first argument.

What is the purpose of the '%x' % n argument?

%x in a string indicates that an item will be formatted to hexadecimal with lowercase letters. '%x' % n. It is similar to the builtin hex function, except it doesn't have the leading 0x in the string. An equivalent expression would be format(n, 'x').
