Relations between NIM-addition and addition

135 Views Asked by At

I will note $\oplus$ the NIM-addition. This is a commutative group law. To obtain $a \oplus b$, you decompose a and b in binary, and you sum like this : 0+0=0 ; 1+0=1 ; 1+1 =0 (it's the xor operation).

For example, $3 \oplus 5 =6$, because 3 is 11 and 5 is 101 so their NIM sum is 110.

We rapidly see that $x \oplus 0=x$, $x \oplus x=0$ and $2p \oplus (2p+1)=1$.

I'm looking for a way to easily obtain $(a+1) \oplus b$ or $(a-1) \oplus b$ or $(a\oplus b-1) $ (an explicite formula).

Thanks!

1

There are 1 best solutions below

3
On

Notice that the operation of incrementing a non-negative integer by 1 is equivalent to changing the last block of "1"s in the binary representation to "0"s and then changing the digit just before that to a "1". If that block had length $k$, then the last $k+1$ digits of $(a+1)⊕b$ is exactly the bitwise negation of the last $k+1$ digits of $a⊕b$, and the other digits are exactly the same. For example:

$101100011111⊕111110001101 = 010010010010$

$101100100000⊕111110001101 = 010010101101$

There is really nothing much more we can say about their relationship without having to use some complicated formula.