mediumBit ManipulationHuluAmazon
Carry-Chain Adder
An ALU designer implements integer addition using only XOR and AND gates (no '+' operator).
Given two integers a and b, return their sum WITHOUT using the operators + and -.
Choose approach
1
02
1Mapstate
a→00000001
b→00000010
carry→00000000
1/2
Narrationstep 1 of 2
a=00000001, b=00000010 → sum-no-carry 00000011, carry 00000000.
Variables
a=1
b=2
carry=0
nextA=3
How to think about it
- Classic half-adder composition.
- Terminates once the carry chain exits all bits.
Edge cases to catch in interview
- Negatives via two's complement.
- Overflow wraps per fixed word size.
Examples
Example 1
5{"a":2,"b":3,"values":[2,3]}
Try your own input
SpacePlay / pause
← / →Previous / next step
RReset to start
. or >Cycle speed