Huffman Coding: Bits, Bytes, and Details

For the first part of these problems, the Huffman tree below will be used to uncompress a file.
*

Decoding bits

Part 1

The two bit streams below are similar, but near the end of the streams the bits differ. Using either the top or bottom sequence, decode/uncompress what the bits represent. Explain the problem in the top bit stream that is fixed by the bottom bit stream.

010 111 000 110 111 011 110 110 010 001 10

010 111 000 110 111 011 110 110 010 001 101 001 011 000 101 110






Part 2

Suppose that 4 bits at a time are used when compressing a file rather than 8. This means the loop to read will be similar to the code below:

while (ib.Readbits(4,num)) { myTable[num]++; } Using the ASCII table below, and converting decimal values to binary values, show what the table will look like for compressing the file
    tsar star 

The letter 't' has ASCII value 116 which is represented in binary as 01110100. This means the first two values read by the loop above will be 0111 (which has decimal value 7) and 0100 (which has decimal value 4). Complete the table below that results from reading "tsar star":

		            
   0                      8 
		            
   1		          9 
		            
   2		         10 
		            
   3		         11 
		            
   4		         12 
		            
   5		         13 
		            
   6		         14 
		            
   7		         15 

Part 3

How many bits will be written at the beginning of the compressed file to store

  1. The entire table above if all 16 values are written and 8 bits are used to write each value (8 bits can represent numbers between 0 and 256, no count in the table above is greater than 256).

  2. The entire table above if only non-zero values are written, and the minimum number of bits is used to write all the values. This minimum number of bits must be written also --- before the non-zero values are written (use 8 bits to write the number of bits).

decimal char decimal char decimal char decimal char
0 ^@ 32 space 64 @ 96 ` (back quote)
1 ^A! 33 ! 65 A 97 a
2 ^B 34 " 66 B 98 b
3 ^C 35 # 67 C 99 c
4 ^D 36 $ 68 D 100 d
5 ^E 37 % 69 E 101 e
6 ^F 38 & 70 F 102 f
7 ^G (bell) 39 ' (apostrophe) 71 G 103 g
8 ^H (backspace) 40 ( 72 H 104 h
9 ^I (tab) 41 ) 73 I 105 i
10 ^J (line feed) 42 * 74 J 106 j
11 ^K 43 + 75 K 107 k
12 ^L 44 , (comma) 76 L 108 l
13 ^M (carriage return) 45 - 77 M 109 m
14 ^N 46 . 78 N 110 n
15 ^O 47 / (slash) 79 O 111 o
16 ^P 48 0 80 P 112 p
17 ^Q 49 1 81 Q 113 q
18 ^R 50 2 82 R 114 r
19 ^S 51 3 83 S 115 s
20 ^T 52 4 84 T 116 t
21 ^U 53 5 85 U 117 u
22 ^V 54 6 86 V 118 v
23 ^W 55 7 87 W 119 w
24 ^X 56 8 88 X 120 x
25 ^Y 57 9 89 Y 121 y
26 ^Z 58 : 90 Z 122 z
27 escape 59 ; 91 [ 123 {
28 fs 60 < 92 \ 124 |
29 gs 61 = 93 ] 125 }
30 rs 62 > 94 ^ 126 ~ (tilde)
31 us 63 ? 95 _ 127 del

Owen L. Astrachan
Last modified: Wed Apr 23 11:57:37 EDT