[Question]
  [
The goal of this challenge is to generalise the bitwise XOR function to other bases. Given two non-negative integers \$ x \$ and \$ y \$, and another integer \$ b \$ such that \$ b \geq 2 \$, write a program/function which computes the generalised XOR, described the following algorithm:
1. First, find the base \$ b \$ representation of \$ x \$ and \$ y \$. For example, if \$ b = 30 \$ and \$ x = 2712 \$, then the digits for \$ x \$ would be \$ [3, 0, 12] \$. If \$ y = 403 \$, then the digits for \$ y \$ would be \$ [13, 13] \$.
2. Next, pairwise match each digit in \$ x \$ with its corresponding digit in \$ y \$. Following on from the previous example, for \$ b^0 \$ we have \$ 12 \$ and \$ 13 \$, for \$ b^1 \$ we have \$ 0 \$ and \$ 13 \$, and for \$ b^2 \$ we have \$ 3 \$ and \$ 0 \$.
3. Let \$ p \$ and \$ q \$ be one of the pairs of digits. The corresponding digit in the output will be equal to \$ -(p + q) \bmod b \$, where \$ \bmod \$ is the modulo function in the usual sense (so \$ -1 \bmod 4 = 3 \$). Accordingly, the output digit for \$ b^0 \$ is \$ 5 \$, the next digit is \$ 17 \$, and the final is \$ 27 \$. Combining the output digits and converting that back to an integer, the required output is \$ 5 \cdot 30^0 + 17 \cdot 30^1 + 27 \cdot 30^2 = 24815 \$.
This definition retains many of the familiar properties of XOR, including that \$ x \oplus\_b y = y \oplus\_b x \$ and \$ x \oplus\_b y \oplus\_b x = y \$, and when \$ b = 2 \$ the function behaves identically to the usual bitwise XOR.
This challenge is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest code in bytes wins. You may not accept/output digit arrays of base \$ b \$, and your code should work in theory for all bases, and not be limited by builtin base conversion which limit your program/function from working for say \$ b > 36 \$. However, assuming that your integer data type width is sufficiently large is fine.
## Test cases
Formatted as `x, y, b => output`
```
2712, 403, 30   => 24815
24815, 2712, 30 => 403
27, 14, 2       => 21
415, 555, 10    => 140
0, 10, 10       => 90
10, 0, 10       => 90
52, 52, 10      => 6
42, 68, 10      => 0
1146, 660, 42   => 0
```
  
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 7 bytes
```
bUSN%Uḅ
```
[Try it online!](https://tio.run/##y0rNyan8/z8pNNhPNfThjtb/D3euOrzcQfP//2gjc0MjHQUTA2MdBWODWB2FaCMTC0NTHQWIOFTIXEfB0AQoBuKYgGRNTYGEIVjSAMSAcUAsOMcUaAAIQ3gmQJaZBVyhoYkZkG8GVGxiFAsA "Jelly – Try It Online")
-3 byte thanks to Unrelated String
```
bUSN%Uḅ  Main link; take [x, y] on the left and b on the right
b        Convert x and y to base b
 U       Upend; reverse each of x and y's digits
  S      Sum; vectorizes
   N     Negate
    %    Modulo with b
     U   Upend; reverse the digits
      ḅ  Convert from base b
```
The double reverse is necessary such that the digits line up on the correct side should one digit list be shorter than the other.
Almost all ASCII!
[Answer]
# [Vyxal](https://github.com/Lyxal/Vyxal), ~~14~~ ~~13~~ 11 bytes
```
vτR÷+N⁰%Ṙ⁰β
```
[Try it Online!](http://lyxal.pythonanywhere.com?flags=&code=v%CF%84R%C3%B7%2BN%E2%81%B0%25%E1%B9%98%E2%81%B0%CE%B2&inputs=%5B2712%2C%20403%5D%0A30&header=&footer=)
Takes `[x, y]` and `b` and outputs the result.
*-1 thanks to the power of vectorisation*
*and -2 thanks to porting Jelly*
## Explained (old)
```
vτR÷Zv∑N⁰%Ṙ⁰β
vτ             # Convert x and y to base b
  R            # reverse each result
   ÷Z          # zip the digits
               # to each pair of digits ([p, q]):
     v∑N       #     -(p + q)
        ⁰%     #     % b
          Ṙ    # reverse the result of the above map and
           ⁰β  # convert it from base b to base 10
```
[Answer]
# [Python 2](https://docs.python.org/2/), 45 bytes
```
f=lambda b,x,y:x+y and-(x+y)%b+f(b,x/b,y/b)*b
```
[Try it online!](https://tio.run/##ZdDRaoMwGAXg@zzFQRhN1n9tYqPrCvZJdmOosoCzYsMwT@/@VL0YCxjid06UZIjh697n89xWXf3tbjUcTRQv0z6i7m9vkhfqxe1byX50FI9Ovbo5oEKWZSJ/NznB6hPhpAFUV@T2bArxnAlLzhEH3OI@wVh2LCP1jbCpWhQ8Gb2qsVro9L7Zwh9aJPqvBf8mPRuzlsIylOc/yPuNLZlL/obNN@SzHB5h9INUh8fQ@SB3n/1OifY@ooPvES4C8ISGD96tlay6Zop5IkSC46T5qTvpkw2j74N83hpFhWrNGkXYUM2/ "Python 2 – Try It Online")
The \$\text{div}\$ and \$\text{mod}\$ operator in Python 2 work much better than JavaScript in this challenge...
[Answer]
# [J](http://jsoftware.com/), 16 bytes
```
[#.[|[:-@+/#.inv
```
[Try it online!](https://tio.run/##XY0/C8IwEMV3P8XDDkW0MZdeYg0UBMHJyTWjWKqDbk5@93hpagvC/eP33t094lKVHVqPEhtoeMlK4Xg5n2IoVPgEXx3W20Ldn@@4Wtyu/QuGG7JoUWt0MDsyYF1nSYZJGFxJHrdIFDNsgDgzYi2Qkp3FbK3NfD9hLe2fSRmZ@yFrJDKbLxq4ZmacfhOxg3M6fgE "J – Try It Online")
Just a straight translation of the algorithm:
* `#.inv` Convert to base `b`
* `[:-@+/` Negative of elementwise sum
* `[|` Mod by `b`
* `[#.` Convert back to decimal
[Answer]
# [C (gcc)](https://gcc.gnu.org/), ~~65~~ ~~47~~ 45 bytes
No bytes added or saved but thanks for a bug fix by [Chris Bouchard](https://codegolf.stackexchange.com/users/45870/chris-bouchard)!!!
```
f(x,y,b){x=x+y?~-b*(x+y)%b+b*f(x/b,y/b,b):0;}
```
[Try it online!](https://tio.run/##bZJtb4IwEMff@ykuJCY8HJGHgjrG9mLZp5hmsVgc2YYLkKzMsI8@dpVi1EjyL6X/@90dbTN3l2V9n5sSW@TWQabSaR9/XW6bNLGm3OE2mTOOLYlbd17S9UXZwOemKE1rcpgAPWqhEXXzKl/WkMIhxGDuBwgBW/gRveYITE08BJ8UkcVIvs/iLrnM0I4ZmBcqUqXxGTFRNMCajxek2LvG@YAzDClOKRioa7HgjBTyS2SN2A5sgLrtoQNf1SdiqRUfWxgLZ2@byqZRZO@iIh5UBmMln4OVXD6RIgPh/Ds0NJnvKzBV9aLcCkmYl@jpPdTFj9jn5tiXNdML9mklAcc5RlswHMH4LyqTPoqjv04u7Ha025s2H21@067JHq/KpSPIOW3jNfpVUUhuGtMtwiBwH9Q4rVcl7Y9EaBE4Qo2nrazTVKx1kW7S9X9Z/rHZ1b37/Q8 "C (gcc) – Try It Online")
[Answer]
# [Ruby](https://www.ruby-lang.org/), 42 bytes
```
f=->x,y,b{x+y<1?0:(-x-y)%b+b*f[x/b,y/b,b]}
```
[Try it online!](https://tio.run/##Zc3NCsIwDAfw83yKgAjqMmy6tJvix4PILj3sLILQIj57TdrhxUNK@f3z8XyFlPN86a4RE4Z3bNOZbua07WKXdpvQhv18j4eASSpMn/yA@W4HsghseoTeTNCswfJIblUy/SHUFkkllMYaDQjEkk2NjlBB1m7n5KHSTGyKG4WKoseKKn/o5JDWor6uFfDjD5dxYi/sZQVbPWbyFw "Ruby – Try It Online")
[Answer]
# [R](https://www.r-project.org/), ~~57~~ 53 bytes
```
f=function(x,b)"if"(any(x),-sum(x)%%b+f(x%/%b,b)*b,0)
```
[Try it online!](https://tio.run/##fc/BDsIgDAbgu0/RaEhAMQIDNg/zXWQJyQ5uyXQJPv0sG6jz4AnC97e0wxT6oZ587ceuebR9RwN3bNv6Lb12TxoYP97HG56EuIOngZyIw8DeccFiKW2oKqXioEXBOBSC7QCgvoDSlTSblIh3DjGYM5jAiuwlB6mR1FwNqYNMrGOxMQYDcukfWWqRXMzvH1z8nFmi/2GDwxu1cmSb/0a11a@@W0tt0W1sr1Ve/WsusVpq0ekF "R – Try It Online")
Using [@tsh's recursive approach](https://codegolf.stackexchange.com/a/226617/55372), taking input as `[x, y], b`.
---
Straightforward, taking input as `[x, y], b`:
### [R](https://www.r-project.org/), ~~69~~ ~~65~~ 64 bytes
```
function(x,b,n=b^(0:max(0,log(x,b))))-(x[1]%/%n+x[2]%/%n)%%b%*%n
```
[Try it online!](https://tio.run/##fc/RCsIgFAbg@57iQAiujDymbgXrRUZBGxRBORgFvv06blqti7wSv//8atf7tiv789M1j2vruBe1cGV95HJ3P3kuxa29hMOM1or7Cg9szdzSV2rYZIzVbMFcaOENVzkqAVpuMgEbmc0BoNyD0gWaWUyEvYAQTBlK0ETyXABqIjVMQ2zAyDoMG2MogGN/YNQyuhzOPzj6NjGS/2FDjzdq4sQ23U1qi199V6O25DbUa5W@/vUuOfnUqP0L "R – Try It Online")
[Answer]
# [APL (Dyalog Extended)](https://github.com/abrudz/dyalog-apl-extended), 10 bytes
Basically a translation of [Jonah's J solution](https://codegolf.stackexchange.com/a/226613/43319).
Tacit infix function. Takes \$b\$ as left argument and \$\{x,y\}\$ as right argument.
```
⊣⊥⊣|∘-+/⍤⊤
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT9dNrShJzUtJTfn//1HX4kddS4FkzaOOGbra@o96lzzqWvI/7VHbhEe9fY@6mh/1rnnUu@XQeuNHbRMf9U0NDnIGkiEensH/jQ0U0hSMzA2NFEwMjLkgPBMLQ1OwGJcRWFLB0ITLECRjAhQ3NTWFcAwUDA0gLCABZZkaARFUrZGCmQWXCcgEQ0MTMwUzMwMA "APL (Dyalog Extended) – Try It Online")
`⍤⊤` convert \$\{x,y\}\$ to base \$b\$, one digit-value per row, padding with leading zeros if needed, then:
 `+/` sum each row
`∘-` negate those sums, then:
 `⊣|` find the remainder when dividing by \$b\$
`⊣⊥` evaluate in base \$b\$
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 11 bytes
Last 5 bytes very similar to the [Vyxal answer](https://codegolf.stackexchange.com/a/226610/64121) ;)
```
вí0ζO(¹%R¹β
```
[Try it online!](https://tio.run/##ASkA1v9vc2FiaWX//9Cyw60wzrZPKMK5JVLCuc6y//8zMApbMjcxMiwgNDAzXQ "05AB1E – Try It Online")
```
в            # convert [x, y] to base b; this results in a list of two lists of digits
 í           # reverse each digit list
  0ζ         # zip with 0 as filler
    O        # sum each pair of digits
     (       # negate all sums
      ¹%     # modulo b
        R    # reverse the resulting base-b digits
         ¹β  # convert from base b
```
[Answer]
# [Red](http://www.red-lang.org), 78 bytes
```
f: func[x y b][either x + y = 0[0][(b * f x / b y / b b)-(x + y % b - b % b)]]
```
[Try it online!](https://tio.run/##LU7RCsIwDHzvV9yLsCnDtmu7IfgTvoY@2K1jvkwpE@bXz7QKyV3uEpKkOO63OJLfpwum9zLQhg@Cp/hY55iw4cT6CknSUxVwxMTeGYHdjKFuqt/MgVXDyVx7XvdM8T7M@O8DCd0pDSNbtFJo0yuL4mTVQRloYdiz1kJJIRkyMxa2GhxcGA3Xl44yDs5JGC28oFd6LGt5Lp/bvw "Red – Try It Online")
My first humble attempt at golfing in Red. This is is the common recursive approach to the problem, but involves a few extra steps in the calculation of the output "digit" because the operators behave quite inconveniently for this task: `%` is remainder, not modulus, while unary minus seems to work only in literals. So, we would need to use verbose function names `negate` and `modulo`, but the shown approach saves a few bytes over that.
[Answer]
# JavaScript (ES6), 44 bytes
* -1 byte by applying a crazy bit-wise expression as suggested by [Arnauld](https://codegolf.stackexchange.com/users/58563/arnauld).
```
b=>g=(x,y)=>(s=~-x-~y)&&s*~-b%b+g(x/b,y/b)*b
```
[Try it online!](https://tio.run/##ZZBRb4IwEIDf@yvuZdpqgRYLczHlbb9CSQRFdKlApBrMMv86uw55MGvSy/W77@6SfmW3rN1dTo31qnpf9Afd5zopNe34nemEtvrhdd7jziaTdvbw8rd8XtIuyPk9yNks7y1o2JLwXYYclFhwWAgA0AmEaikj8hc5DHUsYQEt9DlIhRyG43xJlFOjCIMUTyqVIMK9RzbgD0Ec@k8jXOPuiJHGRCGIly8Q@6WKEcc4Q4Uj3Pr2cjpT5reNOVk63VRT5p@zhnY66TCxuyMNNvt5UA745trmN8ZWxPqH@vKZoWAc/CYAprBQX21zdZ90oGYdpgyjSLlZy5ShsaurtjaFb@qSjqYGsza@KarSHj2Z8ucIXPHDVv0v "JavaScript (Node.js) – Try It Online")
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 17 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
Ouch!
```
®ìV ÔÃÕ®xn uVÃÔìV
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&code=ruxWINTD1a54biB1VsPU7FY&input=WzI3MTIsNDAzXQozMA)
```
®ìV ÔÃÕ®xn uVÃÔìV     :Implicit input of array U=[x,y] and integer V=b
®                     :Map U
 ìV                   :  Convert to base V digit array
    Ô                 :  Reverse
     Ã                :End map
      Õ               :Transpose
       ®              :Map
        x             :  Reduce by addition
         n            :  After negating each
           uV         :  Mod V  
             Ã        :End map
              ìV      :Convert from base V digit array
```
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 18 bytes
```
Ｉ↨⮌Ｅ↨Σθη﹪±Σ÷θＸηκηη
```
[Try it online!](https://tio.run/##S85ILErOT8z5/z@gKDOvRMM5sbhEwymxOFUjKLUstQhI@yYWQASCS3M1CjV1FDKA2Dc/pTQnX8MvNT2xBCLjmVfiklmWmZKqUaijEJBfnlqkkaGjkK0JBCAtMNL6///oaCNzQyMdBRMD41gdBWOD2P@6ZTkA "Charcoal – Try It Online") Link is to verbose version of code. Takes input in the form `[[x, y], b]`. Explanation:
```
      θ             List `[x, y]`
     Σ              Take the sum
    ↨  η            Convert to base `b`
   Ｅ                Map over digits
            θ       List `[x, y]`
           ÷        Vectorised integer divide by
              η     `b`
             Ｘ      Raised to power
               κ    Current index
          Σ         Summed
         ±          Negated
        ﹪       η   Reduced modulo `b`
  ⮌                 Reversed
 ↨                η  Convert from base `b`
Ｉ                    Cast to string
                     Implicitly print
```
[Answer]
# [Core Maude](http://maude.cs.illinois.edu/w/index.php/The_Maude_System), 155 bytes
```
mod X is pr INT . vars B X Y : Nat . op f : Nat Nat Nat -> Nat . eq f(0,0,B)=
0 . eq f(X,Y,B)= B * f(X quo B,Y quo B,B)+((B - 1)*(X + Y))rem B[owise]. endm
```
The answer is obtained by reducing the function `f`, which takes x, y, and b.
### Example Session
```
             \||||||||||||||||||/
           --- Welcome to Maude ---
             /||||||||||||||||||\
         Maude 3.1 built: Oct 12 2020 20:12:31
         Copyright 1997-2020 SRI International
           Tue Jun  1 20:59:00 2021
Maude> mod X is pr INT . vars B X Y : Nat . op f : Nat Nat Nat -> Nat . eq f(0,0,B)=
> 0 . eq f(X,Y,B)= B * f(X quo B,Y quo B,B)+((B - 1)*(X + Y))rem B[owise]. endm
Maude> red f(2712, 403, 30) .
reduce in X : f(2712, 403, 30) .
rewrites: 28 in 0ms cpu (0ms real) (~ rewrites/second)
result NzNat: 24815
Maude> red f(24815, 2712, 30) .
reduce in X : f(24815, 2712, 30) .
rewrites: 28 in 0ms cpu (0ms real) (~ rewrites/second)
result NzNat: 403
Maude> red f(27, 14, 2) .
reduce in X : f(27, 14, 2) .
rewrites: 46 in 0ms cpu (0ms real) (~ rewrites/second)
result NzNat: 21
Maude> red f(415, 555, 10) .
reduce in X : f(415, 555, 10) .
rewrites: 28 in 0ms cpu (0ms real) (~ rewrites/second)
result NzNat: 140
Maude> red f(0, 10, 10) .
reduce in X : f(0, 10, 10) .
rewrites: 19 in 0ms cpu (0ms real) (~ rewrites/second)
result NzNat: 90
Maude> red f(10, 0, 10) .
reduce in X : f(10, 0, 10) .
rewrites: 19 in 0ms cpu (0ms real) (~ rewrites/second)
result NzNat: 90
Maude> red f(52, 52, 10) .
reduce in X : f(52, 52, 10) .
rewrites: 19 in 0ms cpu (0ms real) (~ rewrites/second)
result NzNat: 6
Maude> red f(42, 68, 10) .
reduce in X : f(42, 68, 10) .
rewrites: 19 in 0ms cpu (0ms real) (~ rewrites/second)
result Zero: 0
Maude> red f(1146, 660, 42) .
reduce in X : f(1146, 660, 42) .
rewrites: 19 in 0ms cpu (0ms real) (~ rewrites/second)
result Zero: 0
```
### Ungolfed
```
mod X is
    pr INT .
    vars B X Y : Nat .
    op f : Nat Nat Nat -> Nat .
    eq f(0, 0, B) = 0 .
    eq f(X, Y, B) =
        B * f(X quo B, Y quo B, B)
            + ((B - 1) * (X + Y)) rem B [owise] .
endm
```
[Answer]
# [Pip](https://github.com/dloscutoff/pip), ~~29~~ 23 bytes
```
{Y-$+ay&y%b+b*(fa//bb)}
```
Stretching the input format a bit, this submission is function that takes two arguments: a two-element list containing \$x\$ and \$y\$, and an integer \$b\$. [Try it online!](https://tio.run/##RYyxDoJAEER7v2IKNSoh3C67B/ED6KSzMJcruMLExIKWGL79ODB63bw3kxlfY@z6a/w8yn0xTMfpEIpwOT2HqgrhPEe3g3PcEENM7VEbvwlpSbHqrBqQePAGklpV9aBvadbwAzLIoAzlPwnDtnlIYmFtGku69bjd0fUxlu8F "Pip – Try It Online")
### Explanation
Recursive function idea borrowed from [tsh's Python answer](https://codegolf.stackexchange.com/a/226617/16766).
```
{                     }  A function:
  -$+a                    Negated sum of the first argument (the list of two numbers)
 Y                        Yank that value into y
      y&                  If y is 0 (falsey), return 0; otherwise, return:
        y%b                Negated sum modulo the second argument (the base)
           +               Plus
            b*             The base, times
              (f     )     A recursive call
                a//b       with the two numbers int-divided by the base
                    b      and the same base as before
```
]