Skip to content
Advertisement

Only half of array gets raised to power

I wanted to create binary to decimal calculator. When i tried to console log both of arrays (binary is array of 0’s and 1’s, binarypos is array of numbers that are powers of 2.

Screenshot

Then i created simpler version, made in console so chance of making a mistake lowered to zero. But the bug appears again!

JavaScript

I want it to look like this

JavaScript

Advertisement

Answer

Wouldn’t it be simpler to just do something like this?

JavaScript

Or for what your screenshot suggests that you’re trying to accomplish: converting a string of binary digits (0 or 1) into its decimal representation, just:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement