1 2 >>> int('1010', 2) 3 10
The opposite is a bit involved.
1 2 >>> number = 1000 3 >>> hex2bin = {"0":"0000", "1":"0001", "2":"0010", "3":"0011", 4 "4":"0100", "5":"0101", "6":"0110", "7":"0111", 5 "8":"1000", "9":"1001", "A":"1010", "B":"1011", 6 "C":"1100", "D":"1101", "E":"1110", "F":"1111"} 7 >>> "".join([hex2bin[h] for h in '%X'%number]).lstrip('0') 8 '1111101000'
See the def of toBase2(number) here