[Solved] What is the ^= operator? [closed]


This is the C/C++/C#/Java/Javascript/Perl/PHP/Pike bitwise XOR assignment operator.

An XOR (exclusive or) conditional statement evaluates to true if and only if one of the two operands involved is true.

Example:

0 ^ 0 = false
1 ^ 0 = true
0 ^ 1 = true
1 ^ 1 = false //Regular OR would evaluate this as true

In the same way that you can use += -= *= /= etc… this operator can be combined with an equals sign to perform assignment upon completion.

x += 1; //Same as x = x + 1;
t ^= f; //Same as t = t ^ f;

boolean a = false;
boolean b = true;
a ^= b; //a now evaluates to true;

See Java Operators.

solved What is the ^= operator? [closed]