Do not do addition and subtraction, multiplication and division - to prove safety offer

Title Description

A write function, and the sum of two integers, the function may not be used in vivo requires +, -, *, / four arithmetic symbols.
 
? Thinking: Bit exclusive OR operation rule: no two the same 0 to 1 phase and operation rules: two at the same time is 1 to 1
public  class Solution {
     public  int the Add ( int num1, int num2) {
         // first exclusive OR results obtained in phase to obtain a carry up to carry the end 0 obtained when 
        the while (num2 = 0! {)
             int TEM = num1; 
            num1 = ^ num1 num2;
             // the following two-step calculation carry 
            num2 = TEM & num2; 
            num2 << =. 1 ; 
        } 
        return num1; 
    } 

}

 

Guess you like

Origin www.cnblogs.com/nlw-blog/p/12459104.html