# Thread: XOR operator (^)

1. ## XOR operator (^)

XOR operator (^)

So what is it? The same as 8^3 == 8*8*8 == 512 ?
And what is the storry about XOR. Why is a class needed.

2. Xor is exclusive or. This is not the same as 4 raised to the 3 power. Say you want to xor the number 4 with the number 3. This is how it would look (the numbers are converted into binary)

0000 0100
xor
0000 0011
---------------
0000 0111 (7 in decimal form)

Basically, it is a comparison of bits. If both bits are 0 or 1 in the same spot, then the resulting bit for that spot will be 0. If only 1 of the bits are 1 and the other is 0, the resulting bit for that spot is 1.

3. Does this kinda thing get used much? I know bitwise operation are fast, but in practice do they ever really get used?

4. >but in practice do they ever really get used?
In C, yes, quite a bit. In C++, not as much but for low level programming bit-wise operators are wonderful.

-Prelude

5. >I know bitwise operation are fast, but in practice do they ever really get used?

Yes, as Prelude mentioned, in low level applications, they are very useful, since in such applications you're working a lot with individual bits. Think about datacommunication. You receive telegram consisting of several bytes from a certain device, in such telegrams groups of bits and also individual bits can have a meaning.

But also think about encryption. The XOR is the base for one of the strongest, if not the strongest, encryption techniques, which is the One-Time-Pad. This is based on the property of XOR that:

plain_message ^ key = encrypted_message
encrypted_message ^ key = plain_message

6. The link I posted above details XOR encryption, along with strengths and weaknesses.

7. I've read the site and would like to add something.

For most people's purposes, a key like "(Ta5!34hEf\$" will suffice, but if you need extremely secure encryption, you can take the encrypted text, and XOR it with another key, or you could use a file's contents for the key.
XOR encryption will be uncrackable if the key is as large or larger as the source. This is because then each key is a possible valid key and therefore the encrypted data is uncrackable.

8. >XOR encryption will be uncrackable if the key is as large or larger as the source. This is because then each key is a possible valid key and therefore the encrypted data is uncrackable.

I've edited the article to include this, and given you credit.

Popular pages Recent additions