groovy ^ operator
When given two boolean arguments, the ^ operator performs exclusive or, e.g.
true ^ true == false
true ^ false == true
false ^ true == true
false ^ false == false
When given two numeric arguments, it does something, but I've no idea what. At first I thought it was modular division because
(5 ^ 5) == 0
However
(10 ^ 4) == 14
So it's not modular d开发者_开发百科ivision, is it some kind of bit-shifting?
^
does the same thing as it does in Java and most other languages:
It's a bitwise exclusive OR (short: bitwise XOR)
This means that for every bit in the binary representation of the two numbers the resulting bit in the output will be the bit_in_first_value ^ bit_in_second_value
.
精彩评论