Description

Given two integers a and b, return the sum of the two integers without using the operators + and -. Use bit manipulation with XOR and AND operations.

Examples

Input:a = 1, b = 2
Output:3
Explanation:

1 + 2 = 3 using bit manipulation.

Input:a = -5, b = 3
Output:-2
Explanation:

Adding a negative number (-5) and a positive number (3) results in -2. The bit manipulation approach handles the sign conversion properly by using XOR for addition without carry and AND with left shift for carry propagation.

Input:a = 0, b = 15
Output:15
Explanation:

When one number is 0, the result is simply the other number. In bit manipulation terms, 0 XOR 15 = 15 with no carry bits, making this an edge case that demonstrates the base behavior of the algorithm.

Constraints

  • -1000 ≤ a, b ≤ 1000

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!