Drill

ProblemsPython › network

Single-byte checksum of a payload

easynetworkPython

Many lightweight protocols use a one-byte checksum: just the sum of all bytes modulo 256.

checksum_byte(payload: list<int>) → int

Solve it in the editor →

Where you start

def checksum_byte(payload: list[int]) -> int:
    

Worked examples

CallResult
checksum_byte([1, 2, 3])6
checksum_byte([255, 1])0
checksum_byte([])0
checksum_byte([128, 128])0

Hint

Add every element, then take the remainder when divided by 256.

Reference solution in Python
def checksum_byte(payload: list[int]) -> int:
    return sum(payload) % 256

The same problem in another language

More network problems in Python