6.1 Display the number of bits needed to represent a number

Python solution

View solution

This is just one of many possible solutions:

total_number_of_dots = int(input('Please enter the number of dots: '))
bits = 0
bit_value = 1
while total_number_of_dots >= bit_value:
  bit_value = bit_value * 2
  bits = bits + 1
print(str(bits) + ' bits')

Back to programming challenge