Hi,
I’m pretty new to processing and I came across something like this:
buttonClicked ^= true;
inside a mousePressed() function. What does this “^” do/mean? I did try searching and Googling but I think this character is omitted from all searches.
The ^ symbol is an XOR operation. So x = x ^ y means “If x is true and y is false or x is false and y is true, set x to true. But if x and y are both false, or both true, set x to false.”
Whew.
Of course, in this specific case, y is always true. So x ^= true; means x = x ^ true;, which is the same as x = !x;
In Java, the binary bitwise operators &, | and ^, which normally set & reset bits of integral numbers, are overloaded to deal w/ Boolean values (true & false) as well when both operands are of datatype boolean: