FunctionRacerProblemsRace

How Many Bits Long

BeginnerBitsPython, JavaScript, TypeScript, Java, C++

Return how many bits it takes to write n in binary without zeros in front. For example 5 is 101, which takes 3 bits, and 8 is 1000, which takes 4.

The number 0 is the exception: it has no 1 at all, and the answer for it is 0.

Example 1

n 5
returns 3

5 is 101.

Example 2

n 8
returns 4

8 is 1000.

Example 3

n 0
returns 0

By the rule for 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