On Fri, Jan 28, 2011 at 9:09 AM, tee chwee liong <tc...@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
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to