# bitwise-exclusive-OR operator: ^

• 01-15-2002
mikebrewsj
bitwise-exclusive-OR operator: ^
Can someone please explain to me the ^ operator. I understand it in terms of zeros and ones, but not when integers are involved.

I have the answers to the questions, but I don't understand why:

2^6 = 4
4^0 = 4
4^3^2 = 5 or 2 (i don't know)
1^3 = 3, 4, or 5(i don't know)

I know that for the boolean expression, XOR returns 1(true) if either of the two numbers is one and returns zero(false) if both are zero or both are one. I can not see how to do XOR operator with integers. Please help or let me know where I can find the answer cuz I have looked forever.
• 01-15-2002
SilentStrike
You have to break the integers to bits (literally) for it to make sense.

Code:

2^6

010  2
110  6
100  4

4^0

000  0
100  4
100  4

1^3

01  1
11  3

10  2

4^3^2
4^3
100 4
011 3
111 7

7^2
111 7
010 2
101 5

• 01-15-2002
doubleanti
since you understand that is a bitwise operator, in order to use it correctly with data-types you'd represent in other bases [like integers in base 10] you'd have to grasp them in binary to correctly sequence their effects in your mind. however, if you assign and rewrite your values in hexadecimal, your conceptualization could be easier.