XOR using mathematical operators

前端 未结 9 1596
北海茫月
北海茫月 2021-02-05 09:57

How can I implement XOR using basic mathematical operators like +,-,*,/

Update: Actually, I need to track change in two matrix having Boolean values. T

9条回答
  •  孤城傲影
    2021-02-05 10:18

    you can use this :

    Xor(n,x,y)=x+y - Pow(2,n+1)(floor((x+y)/Pow(2,n+1)));

    when

    x => number in Z collection and positive, x>=0

    y => number in Z collection and positive, y>=0

    n => is data bit length for example 32 or 64

    pow(2,3)=> 222

    floor(1.6594565)=1 or floor(4562.21)=4562

提交回复
热议问题