使用逻辑运算进行加法

public static void main(String[] args) {
        int sum, carry;
        int num1=5,num2=2;
        while(num2 != 0)
        {
            sum = num1 ^ num2;
            carry = (num1 & num2) << 1;
     
            num1 = sum;
            num2 = carry;
        }
        
        System.out.println(num1);
    }

你可能感兴趣的:(使用逻辑运算进行加法)