def dec2bin(num): ''' Convert a decimal integer to base 2.''' if num == 0: return '' num, rem = divmod(num, 2) return dec2bin(num)+str(rem)
>>> dec2bin(1234) '10011010010'
print bin(1234) 0b10011010010
Comment