Memory required to store 1000 telephone numbers

爱⌒轻易说出口 提交于 2019-12-11 03:28:39

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!