← Back to challenges

Binary to Decimal Converter

JavaScriptHardloopsmathnumbers

Instructions

You are given one input: an array containing eight 1's and/or 0's. Write a function that takes an 8 bit binary number and converts it to decimal.

Examples

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

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

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

Notes

Return an integer.

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Repeat the Same Item Multiple Times