function Add(a, b) {
var sum = a ^ b;
var carry = a & b;
while (carry != 0) {
a = sum;
b = carry << 1;
sum = a ^ b;
carry = a & b;
}
return sum;
}
function oppositeNumber(n) {
return Add(~n, 1);
}
function Minus(a, b) {
return Add(a, oppositeNumber(b))
}
function Multiply(a, b) {
if(a==1){
return b;
}
var sum = 0;
var index = 0;
while(index<a){
index = Add(index, 1);
sum = Add(sum, b);
}
return sum;
}
function Add2(num1, num2) {
if(num2 == 0) return num1;//没有进位的时候完成运算
var sum, carry;
sum = num1 ^ num2;//完成第一步没有进位的加法运算
carry = (num1 & num2) << 1;//完成第二步进位并且左移运算
return Add2(sum,carry);//进行递归,相加
}
console.log(Add2(56, 32));
console