[Tutor] What is the augmented assignment operator "^="
Dick Moores
rdm at rcblue.com
Mon Feb 19 12:20:06 CET 2007
At 02:17 AM 2/19/2007, Andre Engels wrote:
>To understand these operators, you will have to think of the numbers
>as binary numbers. Look at the digits. For two numbers x and y, x^y
>is the effect of doing an exclusive or on all digits (that is, 0^1 =
>1^0 = 1 and 0^0 = 1^1 = 0), & of doing an and (1&1 = 1,
>1&0=0&1=0&0=0) and | is an or on all digits (1|1=1|0=0|1 = 1, 0|0 = 0).
>
>So 5^8 = 110 ^ 1000 = 0110 ^ 1000 = 1110 = 13
>and 13^8 = 1110 ^ 1000 = 0110 = 5
Thanks, Andre! I've got it for the three operators, for non-negative
integers. But I'm not sure I understand how negative integers work.
For example, is 3 & -3 = 1
because it is 11 & -11 = 01, and that's because one of the first
digits of 11 and -11 is not 1, and both of their 2nd digits ARE 1, Q.E.D.?
Also, of what practical use are these things?
Dick
More information about the Tutor
mailing list