0
0
Computer Networksknowledge~10 mins

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

Choose your learning style9 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.