Search code examples
xorradixternary

Truth table for XOR function for non binary bases


I know that the XOR operator in base 2 for two bits A and B is (A+B)%2. In others words, it's addition modulo 2.

If I want to compute the truth table for XOR operation in a ternary system (base 3), is it same as addition modulo 3? Eg: In a base 3 system, does 2 XOR 2 = 1 (since (2+2)%3 = 1)?

I read this link which indicated that 2 XOR 2 in a base 3 system is 2 and I can't understand the formula behind that?

In general, for any base 'x', is the XOR operation for that base - addition modulo x?


Solution

  • Well, XOR stands for eXclusive OR and it is a logical operation. And this operation is only defined in binary logic. In your link author defines completely different operator which works the same as XOR for binary base. You may call it an "extension" of XOR operation for bases greater than 2. But as you mentioned in your question, there are multiple ways to do this extension. And each way would preserve some properties of "original" XOR and loose some other. For example, you can stick to observation that

    a ⊕ b = (a + b) mod 2

    In this case your "extended XOR" for base 3 would produce output of 1 for inputs 2, 2. But this XOR3 will no longer satisfy other equations that work for standard XOR, e.g. these ones:

    a ⊕ b ⊕ b = a

    a ⊕ b ⊕ a = b

    If you choose to "save" those, you will get the operation from your link. You can also preserve some different property of XOR, say

    a ⊕ a = 0

    and get another operation that is different from the former two.

    So the short answer is: the phrase "XOR function for non binary bases" doesn't make any sense. XOR operator is only defined in binary logic. If you want to extend it for non-binary bases or non-integer number or complex numbers or whatever, you can do it and define some extension function with whatever behavior and whatever "truth table" you want. But this extension won't be a XOR function anymore.