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.
Think about reading
"110" one bit at a time: after the first bit you have 1, after the second you have 3. What did you do to the 1 to get 3?Each new bit doubles what you have so far, and then adds 1 if the bit is
"1" (or 0 if it is "0").