xxxxxxxxxx
function addWithoutArithmeticOperators(a, b) {
while (b !== 0) {
// Calculate the carry and then perform bitwise addition without carry
let carry = a & b;
a = a ^ b;
b = carry << 1;
}
return a;
}
// Example usage:
const num1 = 5;
const num2 = 7;
const sum = addWithoutArithmeticOperators(num1, num2);
console.log(sum); // Output: 12