Advertisement

XOR semantics

Started by July 11, 2000 03:56 PM
9 comments, last by arunvb 24 years, 5 months ago
This might seem to be a silly question. What does the result we get when we XOR 2 numbers (eg. 15 ^ 36) mean semantically ? Thanks in advance for any help.
In C, that is a bitwise XOR. The result of an XOR is like this on an individual bit:

1 ^ 1 = 0
1 ^ 0 = 1
0 ^ 1 = 1
0 ^ 0 = 0

It means, if either bit is set, but not both, the result is 1.

So, 15 (0000 1111) ^ 36 (0010 0100) would be

0010 1011

Hope that helps!
Advertisement
a xor b = (a|b)&(!(a&b))

----------------
- Pouya / FOO!!!
***CENSORED***
is this one of those cisc / risc things?
Thanks. I know the bitwise semantics but what I am trying to know is the semantics at the integer level.

Eg.

12 -------> 0000 1100
23 -------> 0001 0111
------------------
12 ^ 23 --> 0001 1011 === > 27

What is the relation between 12 ^ 23 and 27 matematically ?

Thanks
Arun
Well, I could be wrong, but I don''t think there is any other mathematical relationship. At least, nothing straightforward. As you can tell already, it isn''t equivalent to any of the basic math operations (add, subtract, mult, etc.).

Anything in particular that you''re trying to use it for? Or just curious about it?
Advertisement
mathematically, neither "and" nor "or" have any relations with the 2 numbers that they were given
in terms of logic (and, or, not) i gave you the description for xor, i say it again:

a xor b = (a or b) and not (a and b)
better now?

----------------
- Pouya / FOO!!!
***CENSORED***
The above is correct, all the bitwise operators have no meaning (well no REAL meaning) when used with anything besides bits.

10100 | 11001 makes sense
4343 | 85 does not make sense, but humans thing in integers, so it''s easier to deal with.

Besides, when was the last time you tried to write the number 5,349,399,993,343 in binary?
quote: Original post by Buster
Besides, when was the last time you tried to write the number 5,349,399,993,343 in binary?


good point
i dont even wanna imagine such a thing. that looks like it''s gonna have 43 binary digits...

----------------
- Pouya / FOO!!!
***CENSORED***
Thanks for your help guys

This topic is closed to new replies.

Advertisement