calculateChecksum method

int calculateChecksum(
  1. ByteData byteData,
  2. int index,
  3. int length,
  4. {int checksum = 0}
)

Implementation

static int calculateChecksum(ByteData byteData, int index, int length,
    {int checksum = 0}) {
  while (length >= 2) {
    checksum = 0xFFFFFFFF & (checksum + byteData.getUint16(index));
    length -= 2;
    index += 2;
  }
  if (length > 0) {
    checksum += byteData.getUint8(index);
    index++;
  }
  checksum = (0xFFFF & checksum) + (checksum >> 16);
  return (0xFFFF & checksum) ^ 0xFFFF;
}