Bitwise operation to add

Could you help me find out why the following expression is true: x + y = x ^ y + (x and y) <1

I am looking for some rules from bitwise logic to explain this mathematical equivalent.

+4
source share
2 answers

This is similar to solving a problem with adding a simple base 955 + 445, first adding all the columns individually and discarding the portable 1s:

    955
    445
  -----
    390

Then we find all the columns where the portable should be 1:

    955
    445
  -----
    101

Shift this and add it to the original result:

   390
+ 1010
------
  1400

, , 1 s, .

2 XOR (^) , 0. 1, , .

x ^ y , x y 1:

   1110111011
^  0110111101
-------------
   1000000110      (x ^ y)

x & y 1 , 1. , :

   1110111011
&  0110111101
-------------
   0110111001      (x & y)

, 1, , , 10.

   1000000110      (x ^ y)
+ 01101110010    + (x & y) << 1
-------------
  10101111000
+8

x + y x ^ y + (x & y) << 1

true , = true. == .


x ^ y + ((x & y) << 1) . , , . XOR , . .

+2

All Articles