+0  
 
0
58
1796
1
avatar+20 

Look at this in Desmos: https://www.desmos.com/calculator/aenqti0xbv

 

153 xor 73 = 208

 

num1 = 15310 = 100110012

num2 = 7310 = 10010012

 

num110011001
num201001001
xor11010000

 

11010002 = 20810

 

-------------------------------------

  1.  We need to know how the xor bit operator works.
  2.  We need to know the binary lengths of x and y.
  3.  We need a function that gets an nth digit from the binary form of x and y.

1)

xor table

xyxor
110
101
011
000

 

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​

off-topic
 Oct 3, 2019
edited by JoshuaGreen  Oct 19, 2019
edited by JoshuaGreen  Oct 22, 2019
edited by JoshuaGreen  Oct 22, 2019
edited by JoshuaGreen  Oct 23, 2019

Best Answer 

 #1
avatar+26367 
+3
 Oct 3, 2019
 #1
avatar+26367 
+3
Best Answer

Mathematical equivalents

see: https://en.wikipedia.org/wiki/Bitwise_operation#OR

 

 

laugh

heureka Oct 3, 2019

5 Online Users

avatar
avatar
avatar