what means: ^=

Hi all! In a stoustrup's file (stings) I found this:
for (int i = 1; i<max; i++) h ^= s.read(i)>>1; // unchecked access to s
I should like somebody explains to me what ^= means. Thanks
It's similar to +=. 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.
Also in that code, 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.


Tutorial on bitwise operations:

http://www.cprogramming.com/tutorial/bitwise_operators.html

http://www.learncpp.com/cpp-tutorial/38-bitwise-operators/


Many thanks to you two !
Topic archived. No new replies allowed.