About

Homework: Exercise 3

Theory: How to Approach These

Jump to: Q1 · Q2 · Q3 · Q4 · Q5


Homework Solutions

Exercise Q1

Write the 7-bit ASCII code for the character 4 using the following encoding: c. Manchester Code d. Frequency modulation e. Modified frequency modulation

Hint: assume 1 is “high,” and 0 is “low.” You may find the ASCII code of “4” using Excel.

PartDetail
AsksFind the 7 ASCII bits of “4”, then draw the signal for those bits in three recording codes.
NeedsASCII digit: 3016+n30_{16} + n. Manchester, FM and MFM rules.
Look at“7-bit” (no parity bit), the character 4 (not the number), “1 is high, 0 is low”.
If it changesOnly the bit string changes; every rule stays. Another character: look up its hex code first.
Show solution ↓
Solution

How to solve

  1. Get the bits: 3416=011 0100234_{16} = 011\ 0100_2. Put the 7 bits above 7 empty cells.
  2. Manchester: 1 = low to high mid-cell, 0 = high to low; add a boundary flip between equal neighbours.
  3. FM: flip at every cell boundary (clock) and mid-cell for each 1.
  4. MFM: flip mid-cell for each 1; boundary flip only between two 0s.
Cell1234567
Bit
Manchester
FM
MFM

Sample answer

The digit “4” is 3016+4=3416=521030_{16} + 4 = 34_{16} = 52_{10}, so the 7 bits are 0 1 1 0 1 0 0.

c. Manchester (7 mid-cell plus 2 boundary flips between equal neighbours, cells 2-3 and 6-7 = 9 transitions):

Waveform diagram0110100bitManchester

d. FM, starting low (3 data flips plus 7 clock flips = 10 transitions):

Waveform diagram0110100bitFM

e. MFM, starting low (3 mid-cell flips plus 1 boundary flip between the 0s in cells 6-7 = 4 transitions):

Waveform diagram0110100bitMFM

Level in the first and second half of each cell:

Cell1234567
Bit0110100
ManchesterHLLHLHHLLHHLHL
FMLLHLHLHHLHLLHH
MFMLLLHHLLLLHHHLL
CodeManchesterFMMFM
Transitions9104

Watch out: “4” is ASCII 011 0100, not binary 100. In Manchester add the boundary flips between equal neighbours (cells 2-3, 6-7). In MFM, cells 1 and 4 are single 0s next to 1s, so they get no boundary flip.

Exercise Q2

Using the CRC polynomial 1101, compute the CRC code word for the information word, 01001101. Check the division performed at the receiver.

PartDetail
AsksFind the CRC bits and the code word sent, then show the receiver’s division leaves remainder 0.
NeedsMod-2 (XOR) long division. Key of n+1n + 1 bits gives an nn-bit CRC.
Look atKey 1101 has 4 bits, so append 3 zeros. Keep the leading 0 of the data.
If it changesLonger key means more zeros and a longer remainder; different data gives a different remainder. The steps stay.
Show solution ↓
Solution

How to solve

  1. Key 1101 has 4 bits, so append 3 zeros: 01001101 becomes 01001101000.
  2. Find the leftmost 1, write the key under it, XOR. Repeat until fewer than 4 bits remain after the last 1.
  3. The last 3 bits are the remainder; put them in place of the zeros to get the code word.
  4. Receiver: divide the whole code word by the key (no zeros added). Remainder 000 means accept.
ItemValue
Key (length)
Zeros appended
Dividend
Remainder (last bits)
Code word = data + remainder
Receiver remainder

Sample answer

Sender, dividend 01001101000:

01001101000
 1101            (step 1)
00100101000
   1101          (step 2)
00010001000
    1101         (step 3)
00001011000
     1101        (step 4)
00000110000
      1101       (step 5)
00000000100  -> remainder 100

Code word = 01001101 + 100 = 01001101100.

Receiver, dividing 01001101100 by 1101:

01001101100
 1101
00100101100
   1101
00010001100
    1101
00001011100
     1101
00000110100
      1101
00000000000  -> remainder 000

Remainder 000, so no error is detected and the word is accepted ✓ (the quotient 1111100 is the same as at the sender).

Watch out: do not drop the leading 0 of the data. Place the key under the leftmost 1, not the leftmost bit. Mod 2 has no borrowing: 1−1=01 - 1 = 0, 0−1=10 - 1 = 1.

Exercise Q3

Compute the minimum Hamming distance of the following code:

0000000101111111
0000001010111111
0000010011011111
0000100011101111
1001000011110111
PartDetail
AsksCompare every pair of code words, count differing bits, and give the smallest count, D(min⁡)D(\min).
NeedsDistance = number of 1s in A XOR B. nn words give n(n−1)/2n(n-1)/2 pairs. Detect D−1D - 1, correct ⌊(D−1)/2⌋\lfloor (D-1)/2 \rfloor.
Look atW5 is the only word starting with 1, so it is far from the rest; the smallest distance is among the first four words.
If it changesnn words give n(n−1)/2n(n-1)/2 pairs; the method is the same.
Show solution ↓
Solution

How to solve

  1. Label the words W1W_1 to W5W_5 and note there are (52)=10\binom{5}{2} = 10 pairs.
  2. For each pair, XOR the words and count the 1s. The table is symmetric, so fill only the top half.
  3. D(min⁡)D(\min) is the smallest entry; then state what the code can detect and correct.
W2W_2W3W_3W4W_4W5W_5
W1W_1
W2W_2–
W3W_3––
W4W_4–––

Sample answer

Pairs worked in full:

W1 = 0000000101111111
W2 = 0000001010111111
XOR  0000001111000000   -> 4 ones

W1 = 0000000101111111
W5 = 1001000011110111
XOR  1001000110001000   -> 5 ones
W1W_1W2W_2W3W_3W4W_4W5W_5
W1W_1–4445
W2W_24–445
W3W_344–45
W4W_4444–5
W5W_55555–

The smallest entry is 4 (every pair among W1W_1 to W4W_4 ties; W5W_5 is 5 away from each):

D(min⁡)=4D(\min) = 4

The code can detect D(min⁡)−1=D(\min) - 1 = 3 errors and correct ⌊(4−1)/2⌋=\lfloor (4-1)/2 \rfloor = 1 error.

Watch out: check all 10 pairs, not just neighbours in the list, and line the 16 bits up in groups of 4 when counting.

Exercise Q4

Suppose we want an error-correcting code that will allow all single-bit errors to be corrected for memory words of length 10. a. How many parity bits are necessary? b. Assuming we are using the Hamming algorithm presented in this chapter to design our error-correcting code, find the code word to represent the 10-bit information word: 1001100110. Assume even parity.

PartDetail
Asks(a) The number of check bits rr for m=10m = 10. (b) Place data and check bits, compute each check bit, write the code word.
NeedsSmallest rr with m+r+1≤2rm + r + 1 \le 2^r. Positions numbered from the right; check bits at 1, 2, 4, 8; PcP_c covers positions whose binary number contains cc.
Look atm=10m = 10, “even parity”, and data order (first data bit goes to the highest position).
If it changesAnother mm changes rr, nn and the coverage lists. Odd parity: each check bit is the opposite value.
Show solution ↓
Solution

How to solve

  1. (a) Try r=3r = 3: 14>814 > 8, no. r=4r = 4: 15≤1615 \le 16, yes. So r=4r = 4 and n=14n = 14.
  2. Write positions 14 down to 1; mark 8, 4, 2, 1 as check bits and fill the data into 14, 13, 12, 11, 10, 9, 7, 6, 5, 3.
  3. Write each position in 4-bit binary; PcP_c covers the positions with a 1 in the cc column. For each check bit, list its data positions and count the 1s: even count gives 0, odd gives 1.
  4. Write the full word and check that every group has an even number of 1s.
Position1413121110987654321
Binary (8 4 2 1)
TypeddddddP8dddP4dP2P1
Bit
CheckData positionsBits there1sValue
P13, 5, 7, 9, 11, 13
P23, 6, 7, 10, 11, 14
P45, 6, 7, 12, 13, 14
P89, 10, 11, 12, 13, 14

Sample answer

(a) 4 parity bits (code word length 14).

(b)

Position1413121110987654321
Binary (8 4 2 1)11101101110010111010100110000111011001010100001100100001
Contents100110P8011P40P2P1

Read the binary row to see which check bits cover a position: each 1 names one check bit. For example, 13 = 1101 has 1s in the 8, 4 and 1 columns, so 13 is covered by P8, P4 and P1. Going the other way, P1 covers every position whose last binary digit is 1, P2 every position with a 1 in the 2s column, and so on.

CheckData bits at its positions1sValue
P1pos 3, 5, 7, 9, 11, 13 = 0, 1, 0, 0, 1, 020
P2pos 3, 6, 7, 10, 11, 14 = 0, 1, 0, 1, 1, 140
P4pos 5, 6, 7, 12, 13, 14 = 1, 1, 0, 0, 0, 131
P8pos 9, 10, 11, 12, 13, 14 = 0, 1, 1, 0, 0, 131
position : 14 13 12 11 10  9  8  7  6  5  4  3  2  1
bit      :  1  0  0  1  1  0  1  0  1  1  1  0  0  0

Code word: 10011010111000

Check (each group including its check bit has an even number of 1s):

  • Group 1 (1, 3, 5, 7, 9, 11, 13): 0, 0, 1, 0, 0, 1, 0, two 1s ✓
  • Group 2 (2, 3, 6, 7, 10, 11, 14): 0, 0, 1, 0, 1, 1, 1, four ✓
  • Group 4 (4, 5, 6, 7, 12, 13, 14): 1, 1, 1, 0, 0, 0, 1, four ✓
  • Group 8 (8, 9, 10, 11, 12, 13, 14): 1, 0, 1, 1, 0, 0, 1, four ✓

Watch out: number positions from the right. P1P_1 covers 13 (odd positions); 14 = 8 + 4 + 2, so P2P_2, P4P_4 and P8P_8 all cover it. Count only data bits, not check positions.

Exercise Q5

Suppose we have retrieved a message and check bits out of the hard disk as 01000011 1010. Find the error bit and correct it using the Hamming code method.

Note: the position of the message is (M8 M7 M6 … M1) and of the check bits (C4 C3 C2 C1).

PartDetail
AsksFind which single bit of the 12 read is wrong and give the corrected word.
Needsm=8m = 8, r=4r = 4, n=12n = 12. Check bits at positions 1, 2, 4, 8 (C1C_1 to C4C_4); message bits fill 3, 5, 6, 7, 9, 10, 11, 12 (M1M_1 to M8M_8). Even parity; the syndrome is the position of the error.
Look atThe labels run from the right: M1M_1 is the rightmost message bit and goes to position 3, C1C_1 is the rightmost check bit and goes to position 1.
If it changesAnother word: same placement and four parity checks. Syndrome 0 means no error.
Show solution ↓
Solution

How to solve

  1. Split the word: M8…M1=01000011M_8 \ldots M_1 = 01000011 and C4C3C2C1=1010C_4 C_3 C_2 C_1 = 1010.
  2. Place the bits at positions 12 down to 1.
  3. For each check bit, add up the 1s in its group including the check bit itself. An odd count means that check fails (1), an even count passes (0).
  4. Read the four results as a binary number s8s4s2s1s_8 s_4 s_2 s_1. That number is the wrong position. Flip that bit.
Position121110987654321
LabelM8M_8M7M_7M6M_6M5M_5C4C_4M4M_4M3M_3M2M_2C3C_3M1M_1C2C_2C1C_1
Bit
GroupPositionsBits1sFails?
11, 3, 5, 7, 9, 11
22, 3, 6, 7, 10, 11
44, 5, 6, 7, 12
88, 9, 10, 11, 12

Sample answer

The message M8…M1=0 1 0 0 0 0 1 1M_8 \ldots M_1 = 0\,1\,0\,0\,0\,0\,1\,1 and the check bits C4C3C2C1=1 0 1 0C_4 C_3 C_2 C_1 = 1\,0\,1\,0 give:

Position121110987654321
LabelM8M_8M7M_7M6M_6M5M_5C4C_4M4M_4M3M_3M2M_2C3C_3M1M_1C2C_2C1C_1
Bit010010010110
GroupPositionsBits1sFails?
11, 3, 5, 7, 9, 110, 1, 1, 0, 0, 131
22, 3, 6, 7, 10, 111, 1, 0, 0, 0, 131
44, 5, 6, 7, 120, 1, 0, 0, 011
88, 9, 10, 11, 121, 0, 0, 1, 020

Syndrome s8s4s2s1=01112=7s_8 s_4 s_2 s_1 = 0111_2 = 7, so position 7 is wrong. Position 7 is M4M_4 (a message bit, not a check bit). Flip it from 0 to 1.

Corrected message: 01001011 (M8…M1)(M_8 \ldots M_1) with check bits 1010. Corrected word, positions 12 to 1: 0100 1101 0110.

Check: with position 7 = 1 the groups hold 4, 4, 2 and 2 ones, all even ✓.

Watch out: the syndrome position counts from the right and includes the check-bit positions. Position 7 is M4M_4, not the 7th message bit from the left. A syndrome that is a power of 2 would mean a check bit itself is wrong.