Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does ^= mean in C/C++?

I have the following line of code:

contents[pos++] ^= key[shift++];

What does operator ^= mean?

like image 256
Serhiy Avatar asked Mar 02 '11 22:03

Serhiy


3 Answers

It is the XOR assignment operator. Basically:

x ^= y;

is the same as:

x = x ^ y;
like image 139
Evan Teran Avatar answered Nov 03 '22 08:11

Evan Teran


This means preform an XOR operation on contents[pos++] using key[shift++] and set contents[pos++] equal to the result.

Example:

contents[pos++]     00010101
key[shift++]        10010001
                    --------
                    10000100
like image 21
Tim Cooper Avatar answered Nov 03 '22 10:11

Tim Cooper


It is a bitwise XOR operator.

x ^= y

is basically

x = x ^ y

of course, this is a bitwise operation

http://en.wikipedia.org/wiki/Bitwise_operation

like image 2
Kyle Avatar answered Nov 03 '22 08:11

Kyle