Saturday, August 6, 2016

Adding without using + operator

function addWithoutPlusOperator (a, b){ // 111, 111
    var sumWithoutCarry = a ^ b; // 000
    var carryWithoutSum =  (a & b) << 1;  //111 << 1 = 1110
    return addWithoutPlusOperator( sumWithoutCarry, carryWithoutSum );
}

No comments:

Post a Comment