问题
I was reading this question,
but didn't understand some part of the aix's answer that how it requires only 17 bits to store 5 digits of the telephone numbers and how the total becomes 2128 bytes to store 1000 numbers.
please help me with this silly doubt.
Thanks in advance...
回答1:
First 5 digits should be stored once, so since 5 digits means a number in 0-99999 in decimal base you need to store at least this in binary.
Now the first binary value which allows you to fit 99999 numbers is 131072, which is 2^17. So 17 bits go for the common prefix.
Now you need to store 1000 5 digits numbers for the lowest part of every single number. Same approach as before. 17 bits per number = 17000 bits.
Total: 17000 + 17 = 17017 bits
.
Every byte has 8 bits, so
17017/8 = 2127.125
.
You need at least 2128 bytes.
回答2:
105 = 100000. ceil(log2(100000)) = 17.
来源:https://stackoverflow.com/questions/11179516/memory-required-to-store-1000-telephone-numbers