Sum an array of 32-bit integers using only bitwise operators
An adder circuit in a CPU has no “plus” instruction to lean on: it builds addition out of XOR, AND, and shifts. In this problem you do the same in JavaScript.
Implement bitwiseTotal(numbers). It returns the sum of every number in the array, computed with bitwise operators only.
bitwiseTotal(numbers) // => number
-2147483648 to 2147483647.2147483647 it wraps around to negative numbers, and below -2147483648 it wraps to positive ones. This is the same result as adding the numbers one at a time with (total + value) | 0.0. Do not change the input array.bitwiseTotal must not contain the characters + or - at all (outside comments and strings). That rules out ++, --, +=, -=, and negative literals such as -1. Use for...of to loop, and ~0 if you need -1.*, /, %, Math, eval, or Function. Write the whole solution inside bitwiseTotal: the tests read its source to check these rules.bitwiseTotal([3, 4]); // => 7
bitwiseTotal([12, -5, 8]); // => 15
bitwiseTotal([-7, -1]); // => -8
bitwiseTotal([]); // => 0
bitwiseTotal([2147483647, 1]); // => -2147483648 (wraps around)
bitwiseTotal([-2147483648, -1]); // => 2147483647
Hint: for two numbers, a ^ b adds every bit position without carrying, and (a & b) << 1 is exactly the carry. Repeat until there is no carry left.