Bird
Raised Fist0
Computer Networksknowledge~10 mins

Error detection (parity, CRC, checksum) in Computer Networks - Interactive Code Practice

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to calculate the parity bit for a given byte.

Computer Networks
def calculate_parity(byte):
    count = 0
    for bit in byte:
        if bit == '1':
            count += [1]
    return '1' if count % 2 != 0 else '0'
Drag options to blanks, or click blank then click option'
A1
B2
C0
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 instead of 1 to count bits.
Adding 2 or more per bit instead of 1.
2fill in blank
medium

Complete the code to compute the checksum by summing all bytes and taking modulo 256.

Computer Networks
def checksum(data):
    total = 0
    for byte in data:
        total += [1]
    return total % 256
Drag options to blanks, or click blank then click option'
Atotal
Blen(byte)
C1
Dbyte
Attempts:
3 left
💡 Hint
Common Mistakes
Adding the length of the byte instead of its value.
Adding a constant instead of the byte.
3fill in blank
hard

Fix the error in the CRC calculation loop by completing the missing operation.

Computer Networks
def crc(data, poly):
    crc = 0
    for bit in data:
        crc = (crc << 1) | int(bit)
        if crc & (1 << (len(poly) - 1)):
            crc = crc ^ [1]
    return crc
Drag options to blanks, or click blank then click option'
Adata
Bpoly
Cbit
Dcrc
Attempts:
3 left
💡 Hint
Common Mistakes
XORing with data or bit instead of the polynomial.
Not XORing at all.
4fill in blank
hard

Fill both blanks to complete the parity check function that returns True if parity matches.

Computer Networks
def check_parity(data, parity_bit):
    count = sum(1 for bit in data if bit == '1')
    return (count [1] 2) == [2]
Drag options to blanks, or click blank then click option'
A%
B==
C!=
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' instead of '==' for comparison.
Using '>' instead of modulo operator.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps each byte to its checksum if checksum is greater than zero.

Computer Networks
checksums = {{'{'}}[1]: [2] for [1], [2] in data.items() if [2] [3] 0{{'}}'}}
Drag options to blanks, or click blank then click option'
Abyte
Bchecksum
C>
Ddata
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'data' as a variable name inside the comprehension.
Using '<' instead of '>' in the condition.

Practice

(1/5)
1. What is the main purpose of error detection methods like parity, CRC, and checksum in data communication?
easy
A. To find mistakes in data transmission
B. To increase the speed of data transfer
C. To compress data for storage
D. To encrypt data for security

Solution

  1. Step 1: Understand the role of error detection

    Error detection methods are designed to identify errors that occur during data transmission.
  2. Step 2: Compare options with the purpose

    Only To find mistakes in data transmission correctly states that these methods find mistakes in data transmission, while others describe unrelated functions.
  3. Final Answer:

    To find mistakes in data transmission -> Option A
  4. Quick Check:

    Error detection = Find mistakes [OK]
Hint: Error detection finds transmission mistakes fast [OK]
Common Mistakes:
  • Confusing error detection with data encryption
  • Thinking error detection speeds up data transfer
  • Mixing error detection with data compression
2. Which of the following correctly describes a parity bit?
easy
A. A bit added to make the total number of 1s even or odd
B. A bit used to encrypt data
C. A bit that compresses the data size
D. A bit that stores the checksum value

Solution

  1. Step 1: Define parity bit function

    A parity bit is added to data to ensure the total number of 1s is either even or odd, helping detect errors.
  2. Step 2: Match options with definition

    A bit added to make the total number of 1s even or odd matches this definition exactly; other options describe unrelated functions.
  3. Final Answer:

    A bit added to make the total number of 1s even or odd -> Option A
  4. Quick Check:

    Parity bit = Even/Odd 1s check [OK]
Hint: Parity bit counts 1s to check even or odd [OK]
Common Mistakes:
  • Thinking parity bit encrypts data
  • Confusing parity bit with checksum
  • Assuming parity bit compresses data
3. Consider a data block with bits: 1101011. If even parity is used, what should be the parity bit added?
medium
A. 0
B. Depends on checksum
C. 1
D. Cannot determine without CRC

Solution

  1. Step 1: Count the number of 1s in the data block

    The bits are 1 1 0 1 0 1 1. Counting 1s: 1+1+0+1+0+1+1 = 5 ones.
  2. Step 2: Determine parity bit for even parity

    Since 5 is odd, to make total number of 1s even, parity bit must be 1.
  3. Final Answer:

    1 -> Option C
  4. Quick Check:

    Odd 1s + parity 1 = even total [OK]
Hint: Count 1s; parity bit makes total even [OK]
Common Mistakes:
  • Counting zeros instead of ones
  • Choosing parity bit 0 when 1 is needed
  • Confusing parity with checksum or CRC
4. A checksum is calculated by summing data bytes and sending the result. If the receiver's checksum does not match, what is the likely problem?
medium
A. Data was compressed incorrectly
B. Data was corrupted during transmission
C. Data was encrypted with wrong key
D. Data was sent too fast

Solution

  1. Step 1: Understand checksum purpose

    Checksum verifies data integrity by comparing sums at sender and receiver.
  2. Step 2: Interpret checksum mismatch

    If checksums differ, data was likely corrupted or changed during transmission.
  3. Final Answer:

    Data was corrupted during transmission -> Option B
  4. Quick Check:

    Checksum mismatch = Data corruption [OK]
Hint: Checksum mismatch means data error [OK]
Common Mistakes:
  • Assuming compression or encryption caused checksum error
  • Ignoring data corruption possibility
  • Thinking transmission speed affects checksum
5. A data packet uses CRC with a generator polynomial of x^3 + x + 1. If the data bits are 1011, which CRC remainder bits should be appended to detect errors?
hard
A. '000' after dividing data by polynomial
B. '000' because CRC always appends zeros
C. '111' after adding parity bit
D. '100' after dividing data by polynomial

Solution

  1. Step 1: Understand CRC calculation

    CRC divides data appended with zeros by the generator polynomial and uses the remainder as CRC bits.
  2. Step 2: Perform division for data 1011 and polynomial x^3+x+1

    Dividing 1011 (with 3 zeros appended) by polynomial gives remainder 100.
  3. Final Answer:

    '100' after dividing data by polynomial -> Option D
  4. Quick Check:

    CRC remainder = '100' [OK]
Hint: CRC remainder from polynomial division is appended [OK]
Common Mistakes:
  • Confusing CRC remainder with parity bits
  • Assuming CRC always appends zeros
  • Skipping polynomial division step
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard