tags:

views:

1283

answers:

5
+10  Q: 

^ operator in java

Can anyone explain the use of ^ operator in java with some examples?Thanks

+15  A: 

This is the same as ^ in most languages, just an XOR.

0 ^ 0 == 0
1 ^ 0 == 1
0 ^ 1 == 1
1 ^ 1 == 0
Cody Brocious
Well, not _any_ language - VB uses ^ for exponentiation.
gkrogers
Yes but VB always uses different stuff anyway... ;)
LePad
+5  A: 

It's bitwise XOR.

http://en.wikipedia.org/wiki/Exclusive_or

empi
+7  A: 
VonC
+1 for the cool image. :)
cletus
+4  A: 

That's the bitwise exclusive OR operation. Check out the Bitwise and Bit Shift Operators section of the Java tutorials for more information.

Zach Scrivena
+4  A: 

In java ^ operator used for bitwise XOR operation.

Follow this link to see the operator precedence also.

http://www.uni-bonn.de/~manfear/javaoperators.php

BlackPanther