Converting a Binary

Warren Postma embed at geocities.com
Tue May 9 12:31:48 EDT 2000


def binstr(n):
 if n <= 1:
  return str(n)
 else:
  return binstr(n/2)+str(n&1)


# test
x = binstr(42)
y = string.atoi(x,2)
print x
print y







More information about the Python-list mailing list