← Back to challenges

Binary Array to Decimal

JavaScriptHardnumbersarraysmath

Instructions

In mathematics and digital electronics, a binary number is a number expressed in the base-2 numeral system or binary numeral system. Given an array of ones and zeroes of a binary number, return the equivalent decimal value.

Examples

binaryToDecimal([0, 0, 0, 1]) ➞ 1

binaryToDecimal([0, 0, 1, 0]) ➞ 2

binaryToDecimal([1, 1, 1, 1, 1, 0, 1, 1, 0, 1]) ➞ 1005

Notes

N/A

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: True Ones, False Zeros