[Tutor] What does ^ and | mean?
Wayne Werner
waynejwerner at gmail.com
Fri Jan 28 16:17:36 CET 2011
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
<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/d94b78ba/attachment.html>
More information about the Tutor
mailing list