📖 Scenario: Imagine you are sending a short message over a noisy channel, like a walkie-talkie or a simple digital communication line. Sometimes, bits can flip from 0 to 1 or 1 to 0 due to noise. To make sure the message is received correctly, we add extra bits called parity bits that help detect and correct errors.
🎯 Goal: You will build a simple program that creates a message with parity bits, checks if the received message has errors, and corrects a single-bit error if found.
📋 What You'll Learn
Create a binary message as a list of 0s and 1s
Add parity bits to the message for error detection
Check the received message for errors using parity bits
Correct a single-bit error if detected
Print the corrected message
💡 Why This Matters
🌍 Real World
Error detection and correction is used in digital communication systems like mobile phones, Wi-Fi, and satellite transmissions to ensure data is received correctly despite noise.
💼 Career
Understanding error correction basics is important for roles in telecommunications, network engineering, and data science where data integrity is critical.
Progress0 / 4 steps
1
Create the original binary message
Create a list called message with these exact bits: 1, 0, 1, 1 representing the original data bits.
Signal Processing
Hint
Think of the message as a list of bits, each bit is either 0 or 1.
2
Add parity bits to the message
Create a list called encoded_message by adding parity bits to message. Use even parity for two parity bits: p1 covers bits 1 and 3, p2 covers bits 2 and 3. Insert p1 at position 0 and p2 at position 2 in the new list.
Signal Processing
Hint
Calculate parity bits by adding the bits they cover and taking modulo 2 for even parity.
3
Detect and correct a single-bit error
Assume received is [0, 1, 1, 0, 1, 1]. Create variables c1 and c2 to check parity bits from received. Calculate error_position as c1 * 1 + c2 * 2. If error_position is not zero, flip the bit at that position in received to correct the error.
Signal Processing
Hint
Use parity checks to find the error position and flip the bit to fix it.
4
Print the corrected message
Print the received list after correction to show the fixed message bits.
Signal Processing
Hint
Use print(received) to show the corrected message.
Practice
(1/5)
1. What is the main purpose of error detection in data transmission?
easy
A. To find mistakes in data using extra bits
B. To increase the speed of data transmission
C. To compress data for storage
D. To encrypt data for security
Solution
Step 1: Understand error detection
Error detection uses extra bits added to data to check if errors occurred during transmission.
Step 2: Identify the main goal
The goal is to find mistakes, not to speed up, compress, or encrypt data.
Final Answer:
To find mistakes in data using extra bits -> Option A
Quick Check:
Error detection = find mistakes [OK]
Hint: Error detection finds mistakes, not speed or compression [OK]
Common Mistakes:
Confusing error detection with encryption
Thinking error detection speeds up data
Mixing error detection with data compression
2. Which of the following is the correct way to represent a parity bit for even parity in a 4-bit data 1011?
easy
A. Add a 1 to make total 1s count odd
B. Add a 0 to keep total 1s count even
C. Add a 1 to keep total 1s count even
D. Add a 0 to make total 1s count odd
Solution
Step 1: Count 1s in data 1011
Data bits: 1,0,1,1 have three 1s (odd count).
Step 2: Determine parity bit for even parity
To make total 1s even, add 0 (no change) would keep count odd, so add 1 to make count 4 (even).
Final Answer:
Add a 1 to keep total 1s count even -> Option C
Quick Check:
3 ones + 1 parity = 4 (even) [OK]
Hint: Count 1s, add parity bit to make total even [OK]
Common Mistakes:
Adding parity bit that keeps count odd
Confusing even and odd parity rules
Ignoring the current number of 1s
3. Given the 7-bit Hamming code 1001101, which bit position (1-indexed from left) contains the error if the parity bits check fails at positions 1 and 4?
medium
A. Position 3
B. Position 6
C. Position 7
D. Position 5
Solution
Step 1: Understand parity check positions
Parity bits in Hamming code are at positions 1, 2, 4. Errors detected at parity 1 and 4 mean bits 1 and 4 parity checks fail.
Step 2: Calculate error position
Add failing parity positions: 1 + 4 = 5. Error is at position 5.
Final Answer:
Position 5 -> Option D
Quick Check:
Sum parity errors = error position 5 [OK]
Hint: Sum failing parity bit positions to find error [OK]
Common Mistakes:
Ignoring parity bit positions
Adding wrong parity positions
Counting bits from right instead of left
4. Identify the error in this parity bit calculation code snippet for odd parity:
data = '1101'
parity = data.count('1') % 2
parity_bit = 1 if parity == 0 else 0
print(parity_bit)
medium
A. Counting 1s is incorrect; should count 0s
B. Parity bit assignment is correct; no error
C. Parity bit logic is reversed; should be 0 if parity is 0
D. Data string should be converted to integer list first
Solution
Step 1: Understand odd parity logic
Odd parity means total 1s including parity bit should be odd. Data '1101' has 3 ones (odd).
Step 2: Check code logic
parity=3%2=1 !=0, so parity_bit=0. Total 3 ones (odd). Logic sets 1 if even count (parity=0), else 0: correct for odd parity.
Final Answer:
Parity bit assignment is correct; no error -> Option B
Quick Check:
3 ones + 0 parity = 3 (odd) [OK]
Hint: Odd parity bit flips when count of 1s is even [OK]
Common Mistakes:
Reversing parity bit assignment
Counting zeros instead of ones
Assuming data type conversion needed
5. You receive a 7-bit Hamming code 0110011. Parity bits are at positions 1, 2, and 4. After checking parity bits, you find errors at positions 2 and 4. Which bit should you flip to correct the error?
hard
A. Bit at position 6
B. Bit at position 3
C. Bit at position 5
D. Bit at position 7
Solution
Step 1: Identify parity bits with errors
Errors at parity bits 2 and 4 mean these parity checks failed.
Step 2: Sum parity error positions
2 + 4 = 6, so the error is at bit position 6.
Step 3: Correct the error by flipping bit 6
Flipping bit 6 fixes the error detected by parity bits 2 and 4.
Final Answer:
Bit at position 6 -> Option A
Quick Check:
Sum parity errors = error bit 6 [OK]
Hint: Sum parity error positions to find bit to flip [OK]
Common Mistakes:
Ignoring parity bit positions
Adding wrong parity positions
Flipping wrong bit position
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.