← all problems

binaryToDecimal 🌶️🌶️

A row of light switches is either on ("1") or off ("0"). Read from left to right, the row is a number written in binary, so "101" is the number 5.

Write a method binaryToDecimal that takes a String bits made only of "0" and "1" characters and returns the number it stands for. The empty String is 0.

For example, binaryToDecimal("101") is 5, and binaryToDecimal("1111") is 15.