#C6594. Add Two Integers Without Using '+' and '-' Operators
Add Two Integers Without Using '+' and '-' Operators
Add Two Integers Without Using '+' and '-' Operators
You are given two integers and your task is to compute their sum without using the direct addition (+) or subtraction (-) operators. Instead, you must use bit manipulation techniques.
The typical solution involves iteratively determining the carry using the bitwise AND and then shifting it left by one position, while updating the sum using the bitwise XOR operator. This process is repeated until there is no carry. In mathematical terms, if we denote the bitwise operations in two's complement arithmetic:
\[ a \oplus b \quad \text{(without carry)}\\ (a \& b) \ll 1 \quad \text{(carry bits shifted)} \]
Once the carry becomes zero, the result is the required sum.
inputFormat
The input consists of a single line containing two space-separated integers \(a\) and \(b\). Both integers will be in the range of 32-bit signed integers.
outputFormat
Output a single integer which is the sum of \(a\) and \(b\) computed without using the '+' or '-' operators.
## sample2 3
5