Sum Without AdditionLoading saved progress…

Sum Without Addition

Add two integers without ever writing + or -. The only tools you get are bitwise operators — the same XOR, AND, and shift gates a CPU's hardware adder uses to add numbers. Your job is to rebuild that adder in JavaScript: XOR produces the digit-by-digit sum, AND followed by a left shift produces the carry, and you repeat until there's no carry left.

Signature

// a, b: 32-bit signed integers (negatives allowed)
// returns: the integer sum a + b, using only bitwise operators
function sumWithoutAddition(a: number, b: number): number;

Examples

sumWithoutAddition(2, 3);   // → 5
sumWithoutAddition(-2, 3);  // → 1
sumWithoutAddition(-5, -3); // → -8
sumWithoutAddition(0, 0);   // → 0
sumWithoutAddition(100, 250); // → 350
sumWithoutAddition(-10, -20); // → -30

Notes

  • No + or - — not in expressions, not in ++/--/+=. Only bitwise operators (^, &, |, <<, >>, >>>, ~) are allowed.
  • Bitwise only — you may not call Math helpers, build strings, or loop with a counter you increment with +. The arithmetic itself must be bitwise.
  • 32-bit signed range — inputs fit in a signed 32-bit integer (roughly −2.1 billion to 2.1 billion). JavaScript's bitwise operators already coerce their operands to 32-bit signed integers, so you don't need a separate big-integer path.
  • Handles negatives-2, -5, and mixed-sign pairs must work. The same bit trick handles them because JS stores negatives in two's complement.
  • Returns the integer sum — a number equal to a + b, not a string or array.
Loading editor…