You're given two integers a and b, and your task is to return their sum without using the addition (+) or subtraction (-) operators.
This is a classic bit manipulation problem that challenges you to think at the binary level. Instead of relying on built-in arithmetic operators, you'll need to simulate addition using bitwise operations - the same way computers actually perform addition at the hardware level!
Goal: Calculate a + b using only bitwise operators like AND (&), OR (|), XOR (^), and bit shifting.
Example: If a = 1 and b = 2, return 3. But remember - no + or - allowed!
Input & Output
Visualization
Time & Space Complexity
In worst case, we iterate once for each bit position, which is logarithmic in the maximum value
Only using a constant amount of extra variables
Constraints
- -1000 โค a, b โค 1000
- No use of + or - operators allowed
- Must handle negative numbers correctly using two's complement