Exchange two numbers without the third number

a = a ^ b

b = a ^ b

a = a ^ b

Explanation:

a = 1000 1101 (b)

b = 1101 0101 (b)

a = a ^ b ======>

 1000 1101 (b) = a

^ 1101 0101 (b) = b

= 0101 1000 (b) = a^b

b = a ^ b ======>

 0101 1000 (b) = a^b

^ 1101 0101 (b) = b

= 1000 1101 (b) = a^b^b=a

a = a ^ b ======>

 0101 1000 (b) = a^b

^ 1000 1101 (b) = a^b^b

= 1101 0101 (b) =a^b^(a^b^b)=a^b^a=b

分享到:

One thought on “Exchange two numbers without the third number

发表评论