How do you do the XOR bitwise operation if you only have available the AND and the OR operations?
相关问题
- Logical vs. bitwise operator AND
- Cast some light on population count algorithm
- XOR Java Neural Network
- Bitwise operation on longs
- Finding the No. of Subset with a Given Xor
相关文章
- Construction an logical expression which will coun
- Rounded division by power of 2
- MySQL doesn't use indexes when query over BIT
- The best way to shift a __m128i?
- Bitwise left shift behaviour
- What is C# exclusive or `^` usage? [closed]
- How do I use Java's bitwise operators in Kotli
- How to find all the subarrays with xor 0?
i am pretty sure that the formula below is correct:
a xor b = not((a and b) or not(a+b))
Truth table for AND
Truth table for OR
Truth table for XOR
So, XOR is just like OR, except it's false if A and B are true.
So, (A OR B) AND (NOT (A AND B)), which is (A OR B) AND (A NAND B)
Not sure if it can be done without NOT or NAND
Best advice is to look up XOR in reference manuals and encyclopedia sites on the net and then write code or script which does the same as the description of what a XOR built-in function does and use your own return or status values. We can not tell you how to do that type of bit compares from within the software community.
(a XOR b) = ((a OR b) - (a AND b))
, or in other words, the union set minus the intersection set.Code example (in javascript):
Wikipedia's entry on XOR goes over this in detail. Probably a good first place to check before aksing a SO question.
If you already have bits you don't care about masked off, it seems to me the easiest way to do it (as far as writing the code goes anyway) is to just use your not equal operator.
"The systems ({T, F}, and) and ({T, F}, or) are monoids."
"The system ({T, F}, xor) is an abelian group" which has the property of invertibility unlike monoids.
Therefore, 'and' and 'or' fail to construct 'xor' operation.
Source: https://en.wikipedia.org/wiki/Exclusive_or#Relation_to_modern_algebra