the ^ operator
I saw in the q3 source code they use the ^ operator, so I tryed it on a console application and found out that it does the same as addition. Doing "x ^= 8" appears to do the same as "x += 8". I was wondering why there are two operators for the same operation. Thanks.
the '^' operator is actually the exclusive-or [XOR] bitwise operation... coincidentally... if x is zero... x ^= 8 yeilds the same result as x += 8...
^ is the exclusive OR operator. You're partially correct in that it will add. But only if the bit you're adding is not set in the value your are adding to. 8 has a binary representaion of -
if you exclusive OR it with any value that doesn't have the fourth bit set then you will add it ( same as normal OR) but if you XOR it with
then if one bit or the other are set then it will be set in the result, but if both bits are set then they will be cleared. So if you XOR'ed(^) the above two values, you'd get
I'm not sure how Quake 3 uses XOR, but quite a few games XOR some of the variables they use from primitive encriptition to try and prevent trainers and cheats to be made for them (by those who want to dissassemble them). If you XOR a value with a key you decode it and if you XOR this decoded valued with the original key then you get the original value back again.
My signature below can be decoded in a similar way (the text is the key to the ASCII values).
just curious, where did you see the q3 source?