FW: Re: [Tutor] Quick Question

D-Man dsh8290@rit.edu
Wed, 25 Apr 2001 15:17:24 -0400


Hmm,  I got an error message back and I don't think my post made it to
the list.  I will be away for a couple weeks so I set my filtes to
redirect to /dev/null.  CC any replies to me if you don't want my
filters to drop them.

-D

----- Forwarded message from D-Man <dsh8290@rit.edu> -----

From: D-Man <dsh8290@rit.edu>
Date: Wed, 25 Apr 2001 10:14:25 -0400
To: tutor@python.org
User-Agent: Mutt/1.2.5i
Mail-Followup-To: tutor@python.org

On Wed, Apr 25, 2001 at 04:05:48PM +1000, Glen Wheeler wrote:
|   Hey guys,
| 
|   I've been writing up a bunch of graphing tools in python...just
|   for fun, and on paper I write x squared as x^2 - this is normal
|   for me.  However, in python, it is x**2 - right?

Yes.

|   My question is, what does x^2 do?  It seems like x^y === x + y -
|   is this true?

It might be -- depends on what the values of x and y are :

>>> x = 3
>>> y = 4
>>> print x+y
7
>>> print x^y
7

>>> x = 2
>>> y = 3
>>> print x+y
5
>>> print x^y
1

<grin>



http://www.python.org/doc/current/ref/bitwise.html#l2h-336

The ^ operator yields the bitwise XOR (exclusive OR) of its arguments,
which must be plain or long integers. The arguments are converted to a
common type.


IIRC this operator is the same in Java.  C and C++ don't have a
builtin _logical_ XOR and I don't remember off the top of my head what
the '^' operator does.  I think it might be bitwise negation or
bitwise xor, but I don't think I've ever used it.


In the examples above, in case you're not familiar with binary, 

    3 : 011
    4 : 100
    7 : 111

    2 : 010
    3 : 011
    1 : 001

1 : true
0 : false


HTH,
-D


----- End forwarded message -----