a=0100; print a ; 64 how to reverse this?

Bruno Desthuilliers bruno.42.desthuilliers at wtf.websiteburo.oops.com
Wed Jul 18 09:53:05 CEST 2007


Karthik Gurusamy a écrit :
> On Jul 17, 5:35 am, Bruno Desthuilliers <bruno.
> 42.desthuilli... at wtf.websiteburo.oops.com> wrote:
>> mosi a écrit :
>>
>>
>>
>>> Problem:
>>> how to get binary from integer and vice versa?
>>> The simplest way I know is:
>>> a = 0100
>>> a
>>> 64
>>> but:
>>> a = 100 (I want binary number)
>>> does not work that way.
>>> a.__hex__   exists
>>> a.__oct__ exists
>>> but where is a.__bin__ ???
>>> What`s the simplest way to do this?
(snip)
>>  >>> a = int('100', 2)
>>  >>> a
>> 4
(snip)
> While it's interesting to know we can go from binary to int, the OP
> wanted the other way.

Please reread more carefully the OP's question and code snippet (which 
are just above).




More information about the Python-list mailing list