MediumBit Manipulation · Math

Sum of Two Integers

Given two integers a and b, return their sum without using the + and − operators.

a = 1, b = 1 → 2a = 4, b = 7 → 11

Try:
CALL
1 / 1

Code

The highlighted line runs next. The pill shows the live values in the running call.

Variables

The data structures the code is building

32-bit registers

Two’s complement, bit 31 on the left

Time and space complexity

Integers are 32 bits wide. The highlighted row is the solution being traced.

Keyboard: ← → step, Space play or pause. a and b from −1000 to 1000.