Print a string in binary format

Peter Hansen peter at engcorp.com
Thu Jan 20 21:02:09 EST 2005


neutrino wrote:
> Mmm, the output format that I want is like:
> 0001110011111111000000001111111100000000....
> 
> I tried your code on Cygwin under Windows 2000, and on Linux, but it
> prints out ASCII characters.

Generally speaking, trying to work with binary like that
will drive you mad.  Most people find themselves far more
productive learning to work with hexadecimal, which is nice
in this case since you'll automatically get the hex
representation of any non-printable character if you just
print the string with repr() around it.

-Peter



More information about the Python-list mailing list