2
Copyright M. Baltrush (CS252-
comerr)
4
Hamming Code
•
Detect and correct single error,
parity spread in codeword
Bit Position
1
2
3
4
5
6
7
8
9
10
11
12
P
1
P
2
D
3
P
4
D
5
D
6
D
7
P
8
D
9
D
10
D
11
D
12
P: parity bit
D: data bit
Notice numbering is different: no zero bit, numbering opposite book
Copyright M. Baltrush (CS252-
comerr)
5
Hamming Code Parity Generation
•
n bits of data, k bits of parity
P
1
= XOR( 3, 5, 7, 9, 11 )
Parity generation equations
P
2
= XOR( 3, 6, 7, 10, 11 )
P
4
= XOR( 5, 6, 7, 12 )
P
8
= XOR( 9, 10, 11, 12 )
C = (C
8
C
4
C
2
C
1
)
syndrome for checking
odd parity
Copyright M. Baltrush (CS252-
comerr)
6
Hamming Example
Data: 0 1 0 1 1 1 0 0
Code: P
1
P
2
D
3
P
4
D
5
D
6
D
7
P
8
D
9
D
10
D
11
D
12
P
1
= XOR( 0, 1, 1, 1, 0 ) = 1
P
2
= XOR( 0, 0, 1, 1, 0 ) = 0
P
4
= XOR( 1, 0, 1, 0 ) = 0
P
8
= XOR( 1, 1, 0, 0 ) = 0
0
1
0
1
1
1
0
0
1
0
0
1 0
P
1
= XOR( D
3
, D
5
, D
7
,D
9
, D
11
)
P
2
= XOR( D
3
, D
6
, D
7
, D
10
, D
11
)
P
4
= XOR( D
5
, D
6
, D
7
, D
12
)
P
8
= XOR( D
9
, D
10
, D
11
, D
12
)
Calculation of parity bits
for a byte of information