Hamming codes

From Teletext Wiki
Jump to navigation Jump to search

Teletext uses Hamming error correcting codes to protect important parts of the packet stream from corruption.

Generally speaking all addressing and control information is transmitted with error correction, while the page content for display only has a simple parity bit for rudimentary error detection.

The enhanced teletext specification utilises two different encodings incorporating Hamming protection. These codes enable correction of single bit errors, and detection of double bit errors.

Hamming 8/4

Four data bits are encoded to a single byte along with four parity bits.

The bits are assigned in the following manner (shown Least Significant Bit first):

1 2 3 4 5 6 7 8
P1 D1 P2 D2 P3 D3 P4 D4

D1–4 are data bits, and P1–4 are the parity bits.

Parity bits are calculated by the from the data bits using the exclusive or function (⊕) as follows:

P1 = 1 ⊕ D1 ⊕ D3 ⊕ D4

P2 = 1 ⊕ D1 ⊕ D2 ⊕ D4

P3 = 1 ⊕ D1 ⊕ D2 ⊕ D3

P4 = 1 ⊕ P1 ⊕ D1 ⊕ P2 ⊕ D2 ⊕ P3 ⊕ D3 ⊕ D4

P4 is the overall parity of bits 1–7 and is identical to the parity bit used for standard 7-bit text characters.

Hamming 24/18

Eighteen data bits are encoded in three consecutive bytes in the data stream along with six parity bits. These three bytes are referred to as a triplet.

The bits are assigned in the following manner (shown Least Significant Bit first):

Byte N
1 2 3 4 5 6 7 8
P1 P2 D1 P3 D2 D3 D4 P4
Byte N + 1
9 10 11 12 13 14 15 16
D5 D6 D7 D8 D9 D10 D11 P5
Byte N + 2
17 18 19 20 21 22 23 24
D12 D13 D14 D15 D16 D17 D18 P6

D1–18 are data bits, and P1–6 are the parity bits.

Parity bits are calculated by the from the data bits using the exclusive or function (⊕) as follows:

P1 = 1 ⊕ D1 ⊕ D2 ⊕ D4 ⊕ D5 ⊕ D7 ⊕ D9 ⊕ D11 ⊕ D12 ⊕ D14 ⊕ D16 ⊕ D18

P2 = 1 ⊕ D1 ⊕ D3 ⊕ D4 ⊕ D6 ⊕ D7 ⊕ D10 ⊕ D11 ⊕ D13 ⊕ D14 ⊕ D17 ⊕ D18

P3 = 1 ⊕ D2 ⊕ D3 ⊕ D4 ⊕ D8 ⊕ D9 ⊕ D10 ⊕ D11 ⊕ D15 ⊕ D16 ⊕ D17 ⊕ D18

P4 = 1 ⊕ D5 ⊕ D6 ⊕ D7 ⊕ D8 ⊕ D9 ⊕ D10 ⊕ D11

P5 = 1 ⊕ D12 ⊕ D13 ⊕ D14 ⊕ D15 ⊕ D16 ⊕ D17 ⊕ D18

P6 = 1 ⊕ P1 ⊕ P2 ⊕ D1 ⊕ P3 ⊕ D2 ⊕ D3 ⊕ D4 ⊕ P4 ⊕ D5 ⊕ D6 ⊕ D7 ⊕ D8 ⊕ D9 ⊕ D10 ⊕ D11 ⊕ P5 ⊕ D12 ⊕ D13 ⊕ D14 ⊕ D15 ⊕ D16 ⊕ D17 ⊕ D18

P6 is the overall parity of all bits in the triplet, excluding itself. Unlike the Hamming 8/4 coding, bit 7 in each byte of the triplet is not equivalent to the parity bit of a normal 7-bit teletext character.