Velocity Reviews > integer to binary...

# integer to binary...

Grant Edwards
Guest
Posts: n/a

 06-03-2006
On 2006-06-03, Tim Chase <(E-Mail Removed)> wrote:
>> 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.

>
> Um...let's not use bad logic/proofs for evidencing this...
>
> >>> hasattr(set(), "__xor__")

> True

Sets aren't numbers. Perhaps I should have phrased it better:
xor is only defined for numbers if they are represented in
binary. If numbers were represented in something other than
binary, then an xor operation on those numbers wouldn't make
sense.

--
Grant Edwards grante Yow! .. I want to perform
at cranial activities with
visi.com Tuesday Weld!!

Bruno Desthuilliers
Guest
Posts: n/a

 06-05-2006
Grant Edwards a écrit :
> On 2006-06-02, Bruno Desthuilliers <(E-Mail Removed)> wrote:
>
>>Grant Edwards a écrit :
>>
>>>On 2006-06-01, http://www.velocityreviews.com/forums/(E-Mail Removed) <(E-Mail Removed)> 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.

No, not really.

> Otherwise the bitwise boolean operations you
> demonstrated wouldn't work as shown.

Ho yes ?

>
>>>>>(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

.... objects, instance of the int class. Not really what I'd call "binary
format" !-)

Now if you go that way, it's of course true that everything on a
computer ends up in a binary format.... It's true.

> stored in binary format -- xor is only
> defined for binary numbers.
>

class Prisonner(object):
def __xor__(self, other):
return "I'm not a (binary) number, I'm a free man"

The fact that an object implements the xor operator is pretty much proof
that the guy that wrote the class decided to implement the xor operator !-)

Grant, I of course agree that, *for practical means*, one can consider
that Python's integer are "already in binary format" - for a definition
of "binary format" being "you can do bitwise ops on them". But the truth
is that Python integers are objects (in the OO meaning) holding integer
values - not integer values themselves.