a ^= b
is the same as a = a^b
. ^ is bit-wise exclusive-OR. In a^b
, each bit in the result is set if, in the corresponding bits in a and b, one bit is 1 and the other is 0.
s.read(i)>>1;
is another bitwise operation. The >>
operator means a bitwise right-shift. Shifting right by one position can often be thought of as similar to a divide by 2.