Add a and b and return the sum, without using the + or - operators. Do the work with bit operations instead. Treat both numbers as 32-bit signed integers. Either one can be negative.
Example 1
Input
a = 5, b = 6
Output
11
Explanation
5 is 101 and 6 is 110 in binary. Both have a 1 in the fours place, which carries into the eights place, so the sum is 1011, which is 11.
Example 2
Input
a = 7, b = -7
Output
0
Explanation
7 and -7 cancel out, so the sum is 0. A negative input is allowed.
Constraints:
-1000 <= a, b <= 1000
Tab indents. Press Esc, then Tab to leave the editor.
Ctrl or ⌘ + Enter runs the tests.
Run your code to see every test here. Nothing is submitted or recorded.