AlgoLounge

Sum Two Integers

easy

Given two integers, return their sum without using the + or - operators.

Note: While a simple solution using + works technically, this problem is meant to teach bitwise operations. Avoid using +, -, or built-in addition functions. Use bitwise XOR and AND operations instead.

Example

Example 1

Input:  a = 5, b = 3
Output: 8

Constraints

  • Standard integer range
  • You may not use + or - operators
TypeScript
Loading editor…
List of test cases (10)
Case 1
a = 5
b = 3
Case 2
a = 0
b = 0
Case 3
a = -5
b = 10
Case 4
a = 100
b = 200
Case 5
a = -15
b = -25
Case 6
a = 1000
b = 2000
Case 7
a = -100
b = 100
Case 8
a = 1
b = 1
Case 9
a = -50
b = 25
Case 10
a = 999
b = 1