How to convert a number to binary?

Paul McGuire ptmcg at austin.rr.com
Thu May 17 20:14:09 EDT 2007


"".join([('0','1')[bool(n & 2**i)] for i in range(20) if n>2**i]
[::-1])

Still only valid up to 2**20, though.

-- Paul




More information about the Python-list mailing list