binary literal

Pablo Martí Gamboa pmarti at warp.es
Wed Jul 22 06:24:22 EDT 2009


2009/7/22 superpollo <user at example.net>

> hello clp.
>
> i can insert a hex value for a character literal in a string:
>
> >>> stuff = "\x45"
> >>> print stuff
> E
> >>>
>
> can i do something like the above, but using a *binary* number? (e.g.
> 00101101 instead of 45) ?


(Python 3)

 >>> bin(45)
'0b101101'
>>> int(_, 2)
45

-- 
Pablo Martí
http://www.linkedin.com/in/pmarti || http://www.warp.es
python -c "print '706d6172746940776172702e6573'.decode('hex')"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090722/67261312/attachment-0001.html>


More information about the Python-list mailing list