Drill

ProblemsTypeScript › network

Single-byte checksum of a payload

easynetworkTypeScript

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

checksumByte(payload: list<int>) → int

Solve it in the editor →

Where you start

function checksumByte(payload: number[]): number {
  
}

Worked examples

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

Hint

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

Reference solution in TypeScript
function checksumByte(payload: number[]): number {
  let sum = 0;
  for (const b of payload) sum += b;
  return sum % 256;
}

The same problem in another language

More network problems in TypeScript