Lesson 39: Parity check
이 페이지는 최신 브라우저(SharedArrayBuffer 지원)가 필요합니다. Chrome, Edge, Firefox 또는 Safari를 최신 버전으로 업데이트해 주세요.
English
Did the data arrive safely?
- Data sent down a wire or through the air can change on the way: a 0 becomes a 1.
- A parity check finds many of these errors. The sender adds one extra bit, the parity bit, so the number of 1s is always even (even parity) or always odd (odd parity).
- The receiver counts the 1s. With even parity, an odd count means an error.
Words for this lesson
| Word | Meaning |
|---|---|
| bit | one binary digit: 0 or 1 |
| byte | 8 bits |
| parity bit | the extra bit that makes the count of 1s even (or odd) |
| error | a bit that changed on the way |
English
Even parity
| 7 data bits | 1s | Parity bit | Byte sent |
|---|---|---|---|
| 1100011 | 4 | 0 | 01100011 |
| 1000000 | 1 | 1 | 11000000 |
- If one bit changes on the way, the byte has an odd number of 1s and the receiver knows.
- If two bits change, the count is even again: the error is not found.
English
Count the 1s
void setup() {
Serial.begin(9600);
String bits = "1011";
int ones = 0;
for (int i = 0; i < bits.length(); i++) {
if (bits[i] == '1') {
ones = ones + 1;
}
}
Serial.println(ones);
}
void loop() {
}
- The Monitor shows 3.
English
In the exam
- 0478/12/F/M/23 Q5(c): (i) the bytes are sent with an even parity check: complete the parity bit for each byte. Count the 1s in the other 7 bits and choose 0 or 1 so the total is even, as your first program does. (ii) A parity block check also adds a parity byte for each column of bits, so it can find which bit changed and can find some errors that a byte check misses.
난이도 4/5 · 280코인 + 오늘 첫 완료 시 작은 보너스 추가
Type 7 bits into the Serial Monitor, for example 1100011. Count the 1s. With even parity the total number of 1s must be even, so the parity bit is 1 when the count is odd and 0 when it is even. Print Send: , then the parity bit, then the 7 bits, for example Send: 01100011.
출력을 보려면 '실행'을 클릭하세요.
난이도 4/5 · 280코인 + 오늘 첫 완료 시 작은 보너스 추가
Now be the receiver. Type a whole byte of 8 bits (parity bit first). Count its 1s: if the count is even, print OK and light the green LED (pin 12); if it is odd, a bit was changed on the way: print Error and light the red LED (pin 13). Only one LED is on at a time.
출력을 보려면 '실행'을 클릭하세요.