calculateCRC16 static method

List<int> calculateCRC16(
  1. Uint8List bytes
)

Implementation

static List<int> calculateCRC16(Uint8List bytes) {
  const int polynomial = 0x1021;// CCITT
  const int initVal = 0x0000;// XMODEM
  final bitRange = Iterable.generate(8);

  int crc = initVal;
  for (int byte in bytes) {
    crc ^= (byte << 8);
    for(int e = 0; e < bitRange.length;e++){
      crc = (crc & 0x8000) != 0 ? (crc << 1) ^ polynomial : crc << 1;
    }
  }
  ByteData byteData = ByteData(2)..setInt16(0, crc, Endian.little);
  return byteData.buffer.asUint8List();
}