Address: http://zhedahht.blog.163.com/blog/static/254111742011125100605/
The first response to this question is bitwise computation, but I can't figure out how to perform bitwise computation. I can only see it later. The example given by the blogger is 5 + 17.
Do not carry, calculate 5 + 17 = 12, for example, is the calculation of primary school students, the following 1 is carry
In this way, the last 12 + 10 digits of 1 are 22.
Similarly, binary can also be used. The binary value of 5 is 10001, and the value of 17 is. The calculation method is as follows:
00101
+ 10001
------
10100
+ 10
------
10110
The final calculation is 10110, Which is 22.
It can also be seen from this that in the binary, 1 + 1 and 0 + 0, in-situ 0 + 0 in-situ is 1, and is similar to or
What about carry,Pair0Add0,0Add1,1Add0Not generate carry, only1Add1A carry forward is generated, and the carry is equivalent to <1, so you can start writingProgramNow
1 Int Addwithoutarithmetic ( Int Num1, Int Num2)
2 {
3 If (Num2 = 0 )
4 Return Num1;
5
6 Int Sum = Num1 ^ Num2;
7 Int Carry = (Num1 & Num2) < 1 ;
8
9 Return Addwithoutarithmetic (sum, carry );
10 }