- Suppose you have N different items. You wish to assign each item a unique k bit number, so you can refer to each of them by number, but you want to use as few bits as possible. That is, how small can you make k?
To answer this question, it's useful to think of it from the other side. Suppose you are given k bits. How many different labels could you create?
With k bits, there are 2k different bitstring patterns. Thus, there are 2k different labels.
For example, if you have 3 bits, there are 8 possible bitstrings: 000, 001, 010, 011, 100, 101, 110, and 110. Therefore, you can label up to 8 different items with a unique 3 bit value.
Suppose you wanted to identify 9 different items. 3 bits isn't enough. 4 bits is too many. With 4 bits, you can label 16 different items.
Nevertheless, you need to use 4 bits. Thus, if you have to label N items with a unique k bit bitstring, and you want to minimize k, then you need to solve:
N = 2k
N is fixed. That is, you are specifying N. You want to find out k, realizing that with k bits, there are 2k possible bitstrings.To solve the formular, you take log base 2 of both sides. We use lg to represent log base 2.
lg N = k
Since lg N can be a fraction, and k must be an integer (we can't have fractional bits), then we need to round up.So,
k = ceil( lg N )
the minimum number of bits is the ceiling of lg N which we write as ceil( lg N ). - You might wonder why we care about labelling N different items with as few bits as possible.
In hardware, everything is basically 0's and 1's. For example suppose you have 16 registers, and you want to select one of them. How would you do it? The sensible way to do it is to give each register a unique k-bit bitstring.
Using the formula from the last section, we realize that you need ceil( lg 16 ) = 4. You need 4 bits to identify one of 16 different registers.
You find this happening throughout hardware. You want to identify one of N things, and so you need to use ceil( lg N ) bits to do so.
? 2003 by Charles C. Lin. All rights reserved.
| 只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。 | ||
|
||
網(wǎng)站導(dǎo)航:
博客園
IT新聞
BlogJava
博問
Chat2DB
管理
|
||
|
|
| |||||||||
| 日 | 一 | 二 | 三 | 四 | 五 | 六 | |||
|---|---|---|---|---|---|---|---|---|---|
| 31 | 1 | 2 | 3 | 4 | 5 | 6 | |||
| 7 | 8 | 9 | 10 | 11 | 12 | 13 | |||
| 14 | 15 | 16 | 17 | 18 | 19 | 20 | |||
| 21 | 22 | 23 | 24 | 25 | 26 | 27 | |||
| 28 | 29 | 30 | 31 | 1 | 2 | 3 | |||
| 4 | 5 | 6 | 7 | 8 | 9 | 10 | |||
決定開始寫工作日記,記錄一下自己的軌跡...
常用鏈接
留言簿(4)
隨筆分類(70)
隨筆檔案(71)
charles推薦訪問
搜索
積分與排名
- 積分 - 51915
- 排名 - 448
最新評(píng)論

- 1.?re: 簡(jiǎn)單打印內(nèi)存的小玩意兒
- 不錯(cuò)
- --dddd
- 2.?re: 尋找最長(zhǎng)連續(xù)遞增子序列
- 這個(gè)只能算是方法,效率太低了
- --大物
- 3.?re: 數(shù)單詞數(shù)
- 規(guī)范化;門口麻煩機(jī);那么孔方兄那么媽媽法;釀母菌法那么;風(fēng)格那么明年;憤怒麻煩那么憤怒憤怒留念多孔蕈樂觀好看的里邊趕快巴拿馬城,新年巴拿馬國(guó)際法,不
- --申訴臺(tái)
- 4.?re: 數(shù)單詞數(shù)
- 感到發(fā)現(xiàn)看來自動(dòng)化大會(huì)單行本打開怎么趕快電子管矛盾感動(dòng)不動(dòng)門口‘大批看病黃道婆民主
- --申訴臺(tái)
- 5.?re: 移除字符
- 評(píng)論內(nèi)容較長(zhǎng),點(diǎn)擊標(biāo)題查看
- --D_BOY

