COMP 120 Computer Organization Spring 2006 For any doubts in the following, contact Agam, Room. 023 Problem Set #1 Solution Problem 1. Miss Information [A] First card ca n be any one of 52 possibilities. So when we get to know exactly which card it is (1 possibility) we get Log 2 (52/1) bits = 5.7004 (approx.) bits of information Similarly the 10 th card can be any one of 43 possibilities. So when we get to know exactly which card it is (1 possibility) we get Log 2 (43/1) bits = 5.4263 (approx.) bits of information Finally, the second-last card narrows down the choice of the last card to just 1 and hence turning it over doesn t give us any new information. [ log 2 (1/1) = 0 ] [B] Total possibilities before we know anything = 52 (the number of cards in a deck) After we know it is red, the possibility space decreases by half to 26. Information received = log 2 (52/26) = 1 bit After we know it is a face card, the possibility space shrinks by a ratio of 3/13 (the ratio of face cards to total cards in any suit) Additional information received = log 2 (26/6) = 2.1154 (approx.) bits
After we know it is a diamond, the possibility space shrinks by half again (only two red suits, diamonds and hearts) Additional information received = log 2 (6/3) = 1 bit Remaining bits of information = Additional information received when we know exactly what the card is = log2(3/1) = 1.585 (approx.) bits [C] A -> 0 B -> 10 C -> 11 100101001100000 -> BABBACAAAAA [D] Many ways to do this. One easy way -> Expected number of A s = (0.7)(1000) = 700 Expected length of A strings = (700)(1) = 700 Similarly, length of B strings = (200)(2) = 400 And, length of C strings = (100)(2) = 200 Thus, total length = 700 + 400 + 200 = 1300 Compare with 1000 * log 2 (3/1) = 1584.9625 (slightly more) [D] By formula specified in handout, Information in bits from crooked coin = - [(0.4)log 2 (0.4) + (0.6)log 2 (0.6) ] = - [ (-0.52877) + (-0.44218) ] = 0.97095 By comparison, Information in bits, from fair coin = - 2 (0.5) log 2 (0.5) = 1
[E] Clearly, we have an upper bound for information which is the length of the file = 27358 * 8 bits = 218864 bits For the lower bound, we use the fact that Shakespeare wrote 154 sonnets, and since our information is essentially which sonnet is in the file, Lower bound on information = log 2 154 = 7.2668 (approx.) [F] 4328 bytes = 4328 * 8 bits = 34624 bits Since 7.2668 < 34264 < 218864 This is consistent with the answer to part (e) 2. Modular Arithmetic and 2 s complement Representation [A] A 32-bit word can encode 2 32 bits of information (by definition). And thus 2 32 different values. [B] (6 marks) Representation of 0 = 00000000000000000000000000000000 (32 zeroes) Representation of most positive integer = 01111111111111111111111111111111 (first digit zero, rest all ones) = 2 32 1 = 2147463647 Representation of most negative integer = 10000000000000000000000000000000 (first digit one, rest all zeroes) = -2 32 = -2147463648 Negation of most negative integer = 2 32 which cannot be representation using a 32-bit 2 s complement representation (naively negating it will yield itself as answer) [C] (5 marks) (1) 37 10 = 00000025 16 (2) -32768 10 = FFFF8000 16
(3) 11011110101011011011111011101111 2 = DEADBEEF 16 (4) 10101011101011011100101011111110 2 = ABADCAFE 16 (5) -1 10 = FFFFFFFF 16 [D] ( 6*2 + 3 = 15 marks) (1) 14 + 7 001110 000111 ---------- 010101 = 21 (2) 21-15 010101 110001 --------- 1000110 = 6 (discarding leftmost 1) (3) 15 21 001111 101011 ---------- 000101 = 2 s complement of 000101 = -6 (4) 21 6 010101 111010 ---------- 1001101 = 15 (discarding leftmost 1) (5) -6 + 21 111010 010101 --------- 1001101 = 15 (discarding leftmost 1) (6) 21 + (-21) 010101 101011 --------- 1000000 = 0 (discarding leftmost 1) (7) 21 + 21 010101
010101 ---------- 101010 not = 42 (because of the leftmost 1), as expected in decimal addition of the numbers, but [E] Brief mathematical explanation -A = 0 A = -2 n + (2 n A) = -2 n + [ i 2 +1 A] i = 1 = { -2 n + i 2 i = 1 - A } + 1 Which is basically our complement and add one operation (taking two s complement is to subtracting the number from a series of powers of 2) 3. Rotary Shaft Encoders [A] Slots created as follows: (Shown as a linear strip for convenience) (Previous slots in upper row, new slots in lower row) 0 1 0 1 0 1 0 1 0 0 1 1 0 0 1 1 0 0 As we can see, the 2 bit sequence formed by concatenating the lower sequence with the upper one yields 00, 01, 10, 11 left to right and the reverse from right to left [B] A possible different 3-bit sequence is the following: 000, 001, 011, 010, 110, 111, 101, 100 [C]
In the general case, we have to ensure that successive codes differ by just one digit. One easy way to do it: Divide N into two parts, say n1 and n2, such that n1 + n2 = N Write out numbers from 0 to 2 n1 and 0 to 2 n2 so that they satisfy this property (it is thus a recursive solution). All numbers from 1 to 2 N will fit in a matrix indexed by these two sequences, and adjacent entries satisfy this property (of differing by atmost one digit). Now simply move along adjacent cells till all numbers are covered. 4. Error Detection and Correction [A] (1) bits add up to 13 => error (2) bits add up to 12 => correct (3) bits add up to 13 => error (4) bits add up to 0 => correct [B] (1) Correct data: 0011 0110 0011 011 (2) Correct data: 1100 0000 0101 100 (3) Correct data: 000 101 10 (4) Correct data: 0110 1001
0110 100 [C] When two-bit error occurs in same row or column OR When 2 parity bits, one from the parity column and the other from the parity row are changed, this 2-bit error will be detected as a single-bit error E.g. 011 101 11 If a 2-bit error produces 010 101 01 Then it will be viewed as a single bit error and corrected as: 110 101 01 [D] Bit no. 13 is faulty, with index as 1101 [E] Parity error in p i => e i = 1 i.e. error in p0 => Rightmost bit of index is 1 error in p1 => Second from right bit of index is 1 and so on
[F] Example of 2-bit error that will be missed -> if a parity bit and a bit position in its check subset are both in error (with the bit position being in only one other check subset), the error will be detected as a single-bit error in the parity-bit with the other check subset. A simple modification -> introduce additional parity bit at position 0. 5. Huffman Coding [A] Using our earlier definition, Information per digit = log 2 (10/1) = 3.3219 [B] F(d) = 1 => d = 0 F(d) = 2 => d = 1 / 3 / 7 F(d) = 3 => d = 2 / 5 / 8 F(d) = 5 => d = 4 / 9 F(d) = 7 => d = 6 Information in 1 (1 possibility only) = log 2 (10/1) = 3.3219 (approx.) Information in 3 (3 possibilities) = log 2 (10/3) = 1.737 (approx.) Information in 5 (2 possibilities) = log 2 (10/2) = 2.3219 (approx.) [C] Average amount = weighted sum of all f(d) output values = 2(0.1)(3.3219) + 2(0.3)(1.737) + (0.2)(2.3219) = 0.6643 + 0.4643 + 1.0422 = 2.1708 [D] It will take n-1 iterations each step removes 2 members and adds one member. [E] 3 marks
1 0 1 5 0 2 3 0 1 1 7 Symbol Probability Encoding 1 0.1 000 2 0.3 10 3 0.3 11 5 0.2 01 7 0.1 001 [F] Average length = 3(0.1) + 2(0.3) + 2(0.3) + 2(0.2) + 3(0.1) = 0.3 + 0.6 + 0.6 + 0.4 + 0.3 = 2.2