1print('{0:b}'.format(3)) # '11'
2print('{0:8b}'.format(3)) # ' 11'
3print('{0:08b}'.format(3)) # '00000011'
4
5def int2bin(integer, digits):
6 if integer >= 0:
7 return bin(integer)[2:].zfill(digits)
8 else:
9 return bin(2**digits + integer)[2:]
10print(int2bin(3, 6)) # '000011'