by Pawan Kumar @jsartisan
Given two integers a
and b
, calculate their sum without using the +
or -
operators.
Rules:
- Cannot use addition (+) operator
- Cannot use subtraction (-) operator
- Must handle both positive and negative numbers
- Must return correct sum
Constraints:
- -1000 ≤ a, b ≤ 1000
Examples:
// Example 1:
console.log(getSum(1, 1));
// Output: 2
// Explanation: 1 + 1 = 2
// Example 2:
console.log(getSum(4, 7));
// Output: 11
// Explanation: 4 + 7 = 11
Note: You'll need to use bitwise operations to solve this problem.