Ad
  • Default User Avatar

    The ^= operator performs a bitwise OR (^) and assigns the result to the variable (xor)

    https://docs.oracle.com/javase/tutorial/java/nutsandbolts/operators.html


    What is being done here, is simply taking the XOR of all the numbers (one at a time) to check the last bit.

    XOR means that if both bits are 1, the result is 0, and only if only of the two numbers is 1, the result is 1

    Since odd or even is completely determined by the last (least significant) bit being 1 (odd) or 0 (even), this is all you need to know.

    Hence the final &1 to see if that bit is 1 or not.