Look at this in Desmos: https://www.desmos.com/calculator/aenqti0xbv
153 xor 73 = 208
num1 = 15310 = 100110012
num2 = 7310 = 10010012
num1 | 1 | 0 | 0 | 1 | 1 | 0 | 0 | 1 |
num2 | 0 | 1 | 0 | 0 | 1 | 0 | 0 | 1 |
xor | 1 | 1 | 0 | 1 | 0 | 0 | 0 | 0 |
11010002 = 20810
-------------------------------------
1)
xor table
x | y | xor |
1 | 1 | 0 |
1 | 0 | 1 |
0 | 1 | 1 |
0 | 0 | 0 |
In math, the xor (bitwise) operator can be written as \(|x-y|\)
2) If we want to know the length of binary x, we can use the function below
\(l(x)=\Bigl\lfloor\dfrac{\operatorname{log}(2x)}{\operatorname{log}(2)}\Bigr\rfloor=\lfloor\operatorname{log}_2x\rfloor+1 = \lceil log_2x\rceil\)
3) To get the nth digit from the binary form of a number, we must divide the number by 2 to the power of n and get the remainder of division by 2.
\(d(x,n)=\Bigl\lfloor\dfrac{x}{2^n}\Bigr\rfloor\operatorname{mod}2\)
\(\Bigl\lfloor\dfrac{x}{2^n}\Bigr\rfloor = \lfloor2^{-n}x\rfloor\), so
\(d(x,n)=\lfloor2^{-n}x\rfloor\operatorname{mod}2\)
When we "XORing" something we take nth binary digit of x and y and xor them.
\(|d(x,n)-d(y,n)|\)
We do this for all digits of x and y, so it means that we need a summation \(\sum\)
\(f(x,y)=\sum^{\operatorname{max}(l(x),l(y))}_{n=0}|d(x,n)-d(y,n)|\)
max(l(x), l(y)) - means that we begin to count from the highest order of one of two numbers.
Function output is the sum of ones and zeros obtained using the bitwise operator xor.
1. If you want to get decimal output you should to time xor (bitwise) with 2n
\(\operatorname{xor}(x,y)=\sum^{\operatorname{max}(l(x),l(y))}_{n=0}|d(x,n)-d(y,n)|*2^n\)
\(\operatorname{xor}(x,y)=\sum^{\operatorname{max}(l(x),l(y))}_{n=0}|(\lfloor2^{-n}x\rfloor\operatorname{mod}2)-(\lfloor2^{-n}x\rfloor\operatorname{mod}2)|*2^n \)
2. if you want to get binary output you should to time xor (bitwise) with 10n
\(\operatorname{xor}(x,y)=\sum^{\operatorname{max}(l(x),l(y))}_{n=0}|d(x,n)-d(y,n)|*10^n\)
\(\operatorname{xor}(x,y)=\sum^{\operatorname{max}(l(x),l(y))}_{n=0}|(\lfloor2^{-n}x\rfloor\operatorname{mod}2)-(\lfloor2^{-n}x\rfloor\operatorname{mod}2)|*10^n \)
Thanks a lot to heureka!!!! (See the comments below)
All main operators here: https://www.desmos.com/calculator/41d24kmsvd