crc16 function

int crc16(
  1. List<int> bytes, {
  2. int initial = 0,
})

Implementation

int crc16(List<int> bytes, {int initial = 0}) {
  var crc = initial;

  for (var byte in bytes) {
    int tmp;
    // compute checksum of lower four bits of byte
    tmp = _crcTable[crc & 0xF];
    crc = (crc >> 4) & 0x0FFF;
    crc = crc ^ tmp ^ _crcTable[byte & 0xF];
    // now compute checksum of upper four bits of byte
    tmp = _crcTable[crc & 0xF];
    crc = (crc >> 4) & 0x0FFF;
    crc = crc ^ tmp ^ _crcTable[(byte >> 4) & 0xF];
  }
  return crc;
}