I’ll teach you and not solve, as you asked.
How do you find the amount of digits needed to save a decimal number?
In decimal numerical representation we obviously have 10 different digits. So this is our basis.
The number of digits required is the exponent. So if you have a number 7 you need the first number that is a power of 10. So 10 to 1 is already 10, and 7 fits into 10. So 1 digit is enough to represent that number.
To facilitate and not get the guesswork I can go doing the division by 10 until you reach a number less than 1. Amount of divisions made that you made is the amount of digits required.
If you have the number 56, you need 10 to the 2 to give 100 that would fit the 56. Then you need two digits.
383 fits in 1000, so 10 elevating to 3, so it needs 3 digits and so on.
How many different digits do you have in binary representation? 2, right? So this will be the basis. To find out how many binary digits (bits) you need to test the first exponent that fits the number you want.
Let’s say it had the number 200. You do 2 high to 8 gives 256, so you need 8 bits.
How do I find this out easily? I’ll divide the number by 2 in a row until I reach a number minor that 1. Then 200 needs 8 divisions (would result in 0.78125 that does not interest us).
Let’s say the number is 256. If you make 8 divisions the result is 1. But you should only stop when you give less than 1. Then you need to make one more division. In fact the number 256 needs 9 bits to be represented binarially.
If this is difficult to understand, understand by decimal. How many decimals can be represented with only one digit? 10, obvious, right? But can 10 be represented by a digit? Of course not, it needs 2. Why? Because it starts from 0. then the tenth number is 9. It happens the same with binary.
If the number were 256 it would need 9 bits, since 8 bits can represent 256 numbers, from 0 to 255.
Basically that’s it, now just do the math for these cases of the exercise.
If you have a calculator with this capability you can use logarithm based on 2. But there is a trick that if you give an exact number, you have to add 1 bit. As the number starts at 0, if the number gives exactly the calculated power you need to add a digit. Another way is to add 1 to the number you want to calculate and only then apply the logarithm. So you don’t have to make an exception.
What do you call decimals? There are 3 integers. You are only talking about decimal representation?
– Maniero
@bigown I think "decimals" is supposed to be "base 10".
– Jéf Bueno
That’s basically what you said. You can use a base 2 logarithm if you want to simplify -
2^n = 4095 :: n = log2(4095)
.– bfavaretto