[Tutor] Quick Question
Kalle Svensson
kalle@gnupung.net
Wed, 25 Apr 2001 16:01:39 +0200
Sez Glen Wheeler:
> 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?
No. x^y is x (bitwise xor) y:
>>> x = 4 # 0100
>>> y = 3 # 0011
>>> z = 7 # 0111
>>> x ^ y # 0111
7
>>> x ^ z # 0011
3
^ compares the bits in the operands and bit N in the result is 1 iff either
bit N in the left hand operand or bit N in the right hand operand, but not
both, is 1. Otherwise bit N in the result is 0.
I hope. My brain is all mushy...
Peace,
Kalle
--
Email: kalle@gnupung.net | You can tune a filesystem, but you
Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8)
PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD
[ Not signed due to lossage. Blame Microsoft Outlook Express. ]