crc16 function

int crc16(
  1. List<int> bits
)

CRC-16/CCITT, polynomial x¹⁶ + x¹² + x⁵ + 1 (0x1021), MSB-first, init 0, over bits (each 0 or 1).

Implementation

int crc16(List<int> bits) {
  var crc = 0;
  for (final b in bits) {
    final top = ((crc >> 15) & 1) ^ b;
    crc = (crc << 1) & 0xFFFF;
    if (top == 1) crc ^= 0x1021;
  }
  return crc;
}