需要内存来存储1000个电话号码 [英] Memory required to store 1000 telephone numbers
问题描述
我读<一href="http://stackoverflow.com/questions/7685649/most-efficient-way-to-store-thousand-telephone-numbers">this的问题,
但不明白AIX的答案的某些部分的 它是如何只需要17位来存储5的电话号码的位数以及如何总量为2128个字节来存储1000个号码。
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.
在此先感谢...
推荐答案
高5位应储存一次,所以自5位数是指在十进制0-99999一些需要保存至少这个二进制。
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.
现在的第一个二进制值,它可以让你满足99999号是131072,这是2 ^ 17。因此,17位去的共同preFIX。
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.
现在你需要存储1000 5位数字,每一个数字的最低部分。相同的方法和以前一样。 17 bits每数= 17000位。
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.
总计:17000 + 17 = 17017位
每个字节有8位,所以
八分之一万七千零十七= 2127.125
。
您需要至少 2128字节
这篇关于需要内存来存储1000个电话号码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!