PIXELBANKv8.2.1
Menu

Sum of Two Integers

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

Example:

Input:
1
2
Output:
3
Reasoning:
  • First, we initialize the sum to 0 and store the input values a = 1 and b = 2.
  • Then, we use bitwise operations to add the numbers: a ^ b calculates the sum without considering the carry (12=31 ^ 2 = 3), and a & b calculates the carry (1 & 2 = 0).
  • Since there's no carry (00), the final result is just the sum from the XOR operation: 12=31 ^ 2 = 3.
  • The final output is 33.

Constraints:

  • -1000 <= a, b <= 1000
Editor

Test Results

0/0
Run code to see test results.