Return the sum of integers a and b without using the + or − operators.
a ^ b adds without carrying; (a & b) << 1 is the carry. Repeat until there is no carry left.
1function getSum(a: number, b: number): number {2while (b !== 0) {3const carry = (a & b) << 1;4a = a ^ b;5b = carry;6}7return a;8}
b = 7 ≠ 0, so there is still something to add.
Space: play/pause · ←/→: step