Answer the question
In order to leave comments, you need to log in
How to find the length of a number in bits?
Can you please explain what is the "length of a number in bits", what should be done to determine it?
Let's say Wikipedia says that I need to take a number of 1024 bits, and below is an example, and there is a number, only it seems to me that they have it less.
Please tell us how it works?
Answer the question
In order to leave comments, you need to log in
how is it "the length of the number in bits", what should be done to determine it.
To determine how many bits you need at least to store a number, you need to take its logarithm to base 2 (you first need to add 1, because we also take into account 0). If the result is not an integer (the number is not a power of 2), then it is worth rounding it up:
log2(255 + 1) = 8 - then the number will fit into 8 bits
log2(256 + 1) = 8.0056... - round up to 9
This scheme does not work for 0. You need to remember that it also needs one bit :)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question