hardBit ManipulationPure DSA~30 min
Add Two Integers Without Using + or -
Implement integer addition using only bitwise operations — the way an ALU does it — without the + or - operators.
Problem
Given two integers a and b, return their sum a + b without using the operators + or -. Inputs may be negative; assume 32-bit two's-complement semantics.
Input
Two integers a and b.
Output
An integer: a + b.
Constraints
- -1000 <= a, b <= 1000
- No + or - operators allowed.
- 32-bit two's-complement arithmetic.
Examples
Example 1
Input
a = 1, b = 2
Output
3
Bitwise addition yields 3.
Example 2
Input
a = 2, b = -3
Output
-1
Two's-complement carry propagation gives -1.