unsigned short cksum(unsigned short *addr, int count) { /*Compute Internet Checksum for “count” bytes * beginning at location “addr”. */ register long sum = 0; while ( count > 1 ) { /* This is the inner loop*/ sum += *addr++; coun t -=2; } /* Add left-over byte, if any if ( count > 0 ) sum += *addr;
*/
/* Fold 32-bit sum to 16 bits */ while (sum >>16) sum = (sum & 0xffff) + (sum >> 16) ; }
Leon-Garcia/Widjaja
return ~sum;
Communication Networks
Figure 3.65
(x 7 + x 6 +1) + (x 6 + x 5 ) = x 7 + (1 +1)x 6 + x 5 +1
Addition:
= x 7 + x 5 +1 Multiplication:
2
3
x3 + x2 + x Division: divisor 3 35 ) 122 105 17
Leon-Garcia/Widjaja
2
2
3
(x + 1)(x + x + 1) = x + x + x + x + x + 1 = x + 1
x3 + x + 1 ) x6 + x5 x6 +
= q(x) quotient dividend
x4 + x3 x5 + x4 + x3 x5 + x3 + x2 x4 + x4 +
x2 x2 + x x
Communication Networks
= r(x) remainder Figure 3.66
Steps: 1. Multiply i(x) by xn-k (puts zeros in (n-k) low order positions) Quotient Remainder xn-ki(x) = g(x) q(x) + r(x)
g(x) has degree n-k; g(x) cannot divide d(x) if deg(g(x))> deg(d(x)) z z
z
L = (n-k) or less: all will be detected L = (n-k+1): deg(d(x)) = deg(g(x)) i.e. d(x) = g(x) is the only undetectable error pattern, fraction of bursts which are undetectable = 1/2L-2 L > (n-k+1): fraction of bursts which are undetectable = 1/2n-k
Leon-Garcia/Widjaja
Communication Networks
Figure 3.72
(a) Single bit input (Transmitter) b
+
r (Receiver)
e Error pattern (b) Vector input (Transmitter) b
+
r (Receiver)
e Error pattern
Leon-Garcia/Widjaja
Communication Networks
Figure 3.73
1011100 s=He= 1101010 0111001
1011100 s=He= 1101010 0111001
1011100 s=He= 1101010 0111001
Leon-Garcia/Widjaja
0 0 1 0 0 0 0 0 1 0 0 1 0 0
1
Single error detected
= 0 1
0 1 = 1 + 0 = 1 0
1 1 1 1 0 = 1 + 0 0 0 0
0 1 + 1
Communication Networks
1 1 1
1 0 = 0 1
Double error detected
Triple error not detected
Figure 3.74
s = H r = He 7p s=0
s=0
No errors in transmission (1–p)7
Leon-Garcia/Widjaja
1–3p
Undetectable errors 7p3
Correctable errors 7p(1–3p)
Communication Networks
3p Uncorrectable errors 21p2
Figure 3.75
b1
o
o
o
o
b2
Set of all n-tuples within distance t
Set of all n-tuples within distance t
t=2
Leon-Garcia/Widjaja
Communication Networks
Figure 3.76
L codewords written vertically in array; then transmitted row by row
b1
b2
b3
b4
b1
b2
b3
b4
A long error burst produces errors in two adjacent rows