FunctionRacerProblemsRace

Read a Binary String

BeginnerBitsPython, JavaScript, TypeScript, Java, C++

bits is a number written in binary, as a string of the characters 0 and 1 with the highest bit first. Return the number.

Work it out yourself, bit by bit, without a ready-made conversion. For example "1011" is 8 + 2 + 1 = 11. Zeros in front change nothing: "0011" is 3.

Example 1

bits "1011"
returns 11

8 + 0 + 2 + 1.

Example 2

bits "0011"
returns 3

The two zeros in front add nothing.

Example 3

bits "0"
returns 0

A single 0.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Bits problems