[Tutor] What does ^ and | mean?
tee chwee liong
tcl76 at hotmail.com
Fri Jan 28 16:20:04 CET 2011
thanks for showing the path.. :)
From: waynejwerner at gmail.com
Date: Fri, 28 Jan 2011 09:17:36 -0600
Subject: Re: [Tutor] What does ^ and | mean?
To: tcl76 at hotmail.com
CC: tutor at python.org
On Fri, Jan 28, 2011 at 9:09 AM, tee chwee liong <tcl76 at hotmail.com> wrote:
hi,
i'm confuse on how does ^ and | mean. When i tried |, i thought it is addition but 4|4 also give 4?
They're called bitwise operators:
http://wiki.python.org/moin/BitwiseOperators
+ is the addition operator:
4 + 2 == 6
4 + 4 == 8
| is the bitwise OR
>>> 4|2
6
>>> 4|1
5
>>> 4|3
7
>>> 4|4
4
When i tried ^, looks like subtraction but 2^4 gives 6?
^ is the bitwise XOR
- is subtraction
>>> 2^3
1
>>> 2^2
0
>>> 2^4^ is the XOR operator
6
Pls help to clear my confusion. thanks.
For more information about bitwise operations, wikipedia is your friend!
http://en.wikipedia.org/wiki/Bitwise_operation
HTH,
Wayne
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110128/d756e3fd/attachment.html>
More information about the Tutor
mailing list