Can string formatting be used to convert an integer to its binary form ?

MonkeeSage MonkeeSage at gmail.com
Fri Sep 29 01:08:15 EDT 2006


So far as unobfuscated versions go, how about the simple:

def to_bin(x):
  out = []
  while x > 0:
    out.insert(0, str(x % 2))
    x = x / 2
  return ''.join(out)

Regards,
Jordan




More information about the Python-list mailing list