Outline: Error Checking

• Parity

• Checksum • CRC

Project 1

Error Checking

Detect bit errors and burst errors. Think of an error pattern as being XOR’d with the original message. For example:

 message =  01010101 11110000
 error =  00010000 01000000
 received data = 01000101 10110000

Parity

Add a bit to every byte. For even parity, add the XOR of the bits, for odd parity add the XNOR. ASCII has seven bits, so adding a bit makes it into an even byte. Detects all single-bit errors, about (n − 1)/n two-bit errors (in messages of n bytes). Also detects about x/2 burst errors of length x bytes. Overhead is \frac{1}{7} ≈ 14%.

Checksum

The 16-bit Internet checksum is used over the IP header, over TCP (mandatory) and UDP (optional) header, pseudo-header, and data, and in other Internet protocols. Described in detail in RFC 1071 (http://www.cis.ohiostate.edu/htbin/rfc/rfc1071.html). The checksum is the 1’s complement sum of all pairs of bytes (padded with a zero byte if needed). When checking received data, the checksum must be all 1s. Detects all single-bit errors and almost all actual burst errors, but not reorderings. For messages of n bytes, overhead is \frac{2}{n}, so ≈ 9.5% for n = 21, and ≈ 0.1% for n = 1500.

2’s complement arithmetic

“Normal” binary addition is done in 2’s complement arithmetic. 2’s complement means the negation of a number is the complement of the number, plus one. For example, the negation of 0011 is 1101. In this system, there is exactly one represntation for the value zero, but the range of negative numbers is one greater than the range of positive numbers (with 4 bits, −8 … + 7 is the range).

1’s complement arithmetic

In 1’s complement arithmetic, the negation of a number is the complement of the number. For example, the negation of 0011 is 1100. In this system, there are two represntation for the value zero, all 1s and all 0s, but the ranges of positive and negative numbers are the same. With very few exceptions (these days), computer addition is 2’s complement.

Implementing 1’s complement addition

Fortunately, 1’s complement addition can be implemented using 2’s complement addition. Whenever the addition of two numbers would generate a carry in 2’s complement arithmetic, we simply add the carry back in to the 1’s complement result.

2’s  (10’s)  1’s  (10’s)
1100 + -4 + 1100 + -3 +
0101 = 5 = 0101 = 5 =
1 0001 1(17)  0010  2

Using a 32-bit value to compute the 16-bit checksum, the carries can be accumulated, then added in at the end. The computation is commutative, associative, and byte-order independent.

CRC

Cyclic Redundancy Check is a generic name for a family of error-checking computations. Each individual CRC computation is defined by a polynomial with binary coefficients, e.g. x^{8} + x^{2} + x^{1} + 1. For each such polynomial, we define k as the highest power of x in the polynomial, and also the number of CRC check bits appended to the message; the above polynomial has k = 8. CRCs are used in Ethernet, FDDI, ATM, and a wide variety of other protocols. The mathematical foundations of CRCs are described in the handout.

CRC Performance

All CRCs used in practice detect all all single-bit errors, all double-bit errors, all odd-numbered errors, any burst of length less than k bits, and reorderings. For messages of n bytes, overhead is \frac{k}{8n}. E.g. the overhead is 6.7% for k = 32 and n = 60.

CRC Computation

Given a message G(x) and a k-bit CRC polynomial P (x), the CRC check code R(x) is the k-bit remainder of the division of G(x) by P (x), with all arithmetic being modulo-2 arithmetic. Mathematically, the message to be sent is F (x):

F (x) = x^{k}G(x) − (G(x) mod P (x))

Note that F (x) is always a multiple of P (x). Note that since we are using modulo-2 arithmetic, subtracting R(x) is the same as adding R(x).

CRC Checking

Since a correctly received message is a multiple of P (x), checking the message simply checking that the received message H(x) is a multiple of P (x), i.e. that H(x) mod P (x) = 0 If H(x) = F (x), then H(x) mod P (x) = 0. If on the other hand H(x) = F (x) + E(x) for some non-zero E(x), then

H(x) mod P (x) = E(x) mod P (x)

The selection of P (x) is made on the basis of the many E(x) for which we want

E(x) mod P (x) ≠ 0

so that H(x) mod P (x) ≠ 0 and we will detect the error.

Polynomial Binary Remainder

To compute the remainder R(x) of G(x) mod P (x):

1. Represent each polynomial by a bit string made up of the coefficients of the polynomial, with the MSb representing the highest-power of x.

2. Multiply G(x) by x^{k} by adding k 0s to the right of G(x).

3. Shift P (x) left until it is aligned with the MSb of G(x).

4. Subtract (or add) the shifted P (x) from G(x). Call the result the new G(x). Repeat steps 3-4 until P (x) < G(x).

5. The final G(x) is the desired remainder. Zero-extend it to the left to give it k bits.

Remainder Example

P (x) = x^{3} + 1 = 1001 G(x) = x^{6} + x^{4} + x^{2} + x + 1 = 1010111 k = 3

1010111000 -
1001 =
----
0011111000 -
  1001 =
  ----
  01101000 -
   1001 =
   ----
   0100000 -
    1001 =
    ----
    000100 = remainder

F (x) = x^{9} + x^{7} + x^{5} + x^{4} + x^{3} + x^{2} = 1010111100 Exercise: check F (x) mod P (x) = 0.

Talk about project 1. Talk about the project being available from the

course home page. Next lecture will be about the x-kernel. Talk about selecting teams.

13-1