Question: Write a function NumberOfBits(n) , that takes as input a number, n, where n is bigger or equal to 1, and returns the minimum number

Write a function NumberOfBits(n) , that takes as input a number, n, where n is bigger or equal to 1, and returns the minimum number of bits that n needs to be represented in binary. The number of bits needed for representation in binary for any integer is equal to 1 + the number of times you can divide that number by 2. for example , the number 10 can be divided by 2 three times : 10/2 = 5 , 5/2= 2.5 , 2.5/2 =1.25. thus, 10 need (1 + 3=) 4 digits to be represented in binary as 1010.(provide complete and meaningful docstrings)

>>>NumberOfBits(4) 3

>>>NumberOfBits(15) 4

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!