Yet another solution with another algorithm, by using bitwise operators.
def int2bin(val): res='' while val>0: res += str(val&1) val=val>>1 # val=val/2 return res[::-1] # reverse the string
A faster version without reversing the string.
def int2bin(val): res='' while val>0: res = chr((val&1) + 0x30) + res val=val>>1 return res