integer to binary...

Grant Edwards grante at visi.com
Sat Jun 3 11:06:16 EDT 2006


On 2006-06-02, Bruno Desthuilliers <bdesth.quelquechose at free.quelquepart.fr> wrote:
> Grant Edwards a écrit :
>> On 2006-06-01, nicolasg at gmail.com <nicolasg at gmail.com> wrote:
>> 
>> 
>>>does anyone know a module or something to convert numbers like integer
>>>to binary format ?
>> 
>> 
>> They _are_ in binary format.
>
> Not really.

Yes, really.  Otherwise the bitwise boolean operations you
demonstrated wouldn't work as shown.

>>>> (7).__class__
><type 'int'>
>>>> dir((7))
> ['__abs__', '__add__', '__and__', '__class__', '__cmp__', '__coerce__',
> '__delattr__', '__div__', '__divmod__', '__doc__', '__float__',
> '__floordiv__', '__getattribute__', '__getnewargs__', '__hash__',
> '__hex__', '__init__', '__int__', '__invert__', '__long__',
> '__lshift__', '__mod__', '__mul__', '__neg__', '__new__', '__nonzero__',
> '__oct__', '__or__', '__pos__', '__pow__', '__radd__', '__rand__',
> '__rdiv__', '__rdivmod__', '__reduce__', '__reduce_ex__', '__repr__',
> '__rfloordiv__', '__rlshift__', '__rmod__', '__rmul__', '__ror__',
> '__rpow__', '__rrshift__', '__rshift__', '__rsub__', '__rtruediv__',
> '__rxor__', '__setattr__', '__str__', '__sub__', '__truediv__', '__xor__']
>>>>

The fact that they impliment the xor operator is pretty much
proof that integers are stored in binary format -- xor is only
defined for binary numbers.

-- 
Grant Edwards                   grante             Yow!  ... Blame it on the
                                  at               BOSSA NOVA!!!
                               visi.com            



More information about the Python-list mailing list