-
Make variables called:
- "total number of dots" and set its value to the number entered by the end user.
- “bit value” and set its value to ‘1’. Double its value until it is bigger than the “total number of dots”.
- “bits” and set its value to 0. Every time that you double the “bit value” you need to add a new bit for storing the number (increase the value of “bits” by 1).
-
Use 'Repeat until' block to repeat the blocks until “total number of dots” is greater than the “bit value”. Stop the loop when you find the “bit value” which is larger than the “total number of dots”. Display the value of “bits” as the output.
-
Set the variable “bit value” to ‘1’ and double it (Use the 'Multiply' block under “Operators” to multiply the “bit value” by 2) until it is bigger than the “total number of dots”. Every time that you double the “bit value” you need to add a new bit for storing the number. You can do this by using the 'Change variable by' block to increase the value of variable “bits” value by 1. Use 'Repeat until' block to repeat these steps until condition is true. In this challenge you need to repeat the blocks until “total number of dots” is greater than the “bit value”. Stop the loop when you find the “bit value” is larger than the “total number of dots”.
-
Test your program with some values on the boundaries (for example number 31 would need 5 bits and 32 needs 6 bits).