Course 2.2Lesson 1 of 3
Bits can change on their way along a cable or through the air. This lesson explains how errors happen and why data must be checked after it is sent. Then it shows the simplest check: the parity bit, with even and odd parity.
Try the code and the simulations beside the lesson.
Imagine a friend reads a phone number to you on a noisy bus. You might miss a digit, hear an extra one, or hear a as a . Data on a cable or through the air has the same problems.
Errors can occur during data transmission because of interference: electrical noise from motors, other cables or the weather. There are three kinds of error.
A computer cannot guess which bits are wrong. So the sender adds some extra information, and the receiver uses it to check for errors after the data is transmitted. If an error is found, the data is sent again. This course shows five methods: the parity check, the checksum, the echo check, the check digit and the automatic repeat query.
A parity check uses one extra bit in each byte, called the parity bit. Seven bits hold the data, and the eighth is the parity bit. In this course the parity bit is the leftmost bit, the most significant bit.
Sender and receiver agree in advance to use even or odd parity.
Here is an example. The data is 1001011. It has ones.
01001011.11001011.The check at the other end. The receiver counts the 1s in each byte it receives. With even parity it expects an even count. If the count is odd, at least one bit has changed. The receiver then asks for the byte to be sent again.
A parity check is quick, but it has two weaknesses.
The exam writes algorithms in Cambridge pseudocode. The block below is pseudocode: you read it, but the site cannot run it. It counts the 1s in a byte held in an array of bits and tests even parity.
// Count the 1s in a byte held in Bits[1] to Bits[8]
DECLARE Bits : ARRAY[1:8] OF INTEGER
DECLARE Count : INTEGER
DECLARE Index : INTEGER
Count ← 0
FOR Index ← 1 TO 8
IF Bits[Index] = 1
THEN
Count ← Count + 1
ENDIF
NEXT Index
IF MOD(Count, 2) = 0
THEN
OUTPUT "Even parity: no error found"
ELSE
OUTPUT "Even parity: error found"
ENDIFThe Python program further down does the same job, and you can run it. Python's count("1") replaces the loop, and % does the job of MOD.
The program adds an even parity bit to seven data bits. Then it checks the byte, changes one bit and checks again, and finally changes a second bit.
Try each one on your own first. If you are stuck, open a hint. Then check with Show the answer.
0110100. What is the even parity bit?11010110 arrives. Is there an error?Every lesson is open to read. Enrolling also lets you:
Log in to join the discussion.
Loading…
This lesson is free to read. Enroll free to keep your place and take the tests.