integer to binary...

G

Grant Edwards

Um...let's not use bad logic/proofs for evidencing this...

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.
 
B

Bruno Desthuilliers

Grant Edwards a écrit :
Yes, really.

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

Ho yes ?
(7).__class__


['__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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top