Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.
Shade in the A or B circle for each question.
Draw a line connecting each item on the left to its match on the right.
| Left column | Right column | |
|---|---|---|
| 1checksum = sum(bytes) % 256 | Achecksum = total MOD 256 | |
| 2350 % 256 | BThe bytes are added but the total is never reduced. 350 is greater than 255, so it does not fit in one byte; it needs % 256 to give 94. | |
| 3The first step of a checksum is to add the values of all the bytes in the block together. | CThe total is divided by 255 instead of 256. One byte holds 256 different values, so the modulus must be 256 (the correct answer is 94). | |
| 4If the total is more than 255, only the low byte is kept by taking the remainder after dividing by 256. | Dtotal = 12 + 30 + 8 + 50 | |
| 5checksum = (200 + 100 + 50) % 255 | EAdd up every byte in the block, then keep the remainder after dividing by 256 so the checksum fits in one byte. | |
| 6checksum = 200 + 100 + 50 | FGives 94, because 350 is too big for one byte and 350 - 256 leaves 94. |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
checksum = sum(bytes) % 256 — Add all the byte values in the block, then keep the remainder after dividing by 256 so the result fits in one byte. Example: 200+100+50=350, 350 mod 256 = 94.checksum = sum(bytes) % 256checksum = sum(bytes) % 256checksum = sum(bytes) % 256bytes = [200, 100, 50]
total = sum(bytes)
checksum = total % 256# 200 + 100 + 50 = 350
checksum = 350 % 256
print(checksum) # 94