crcInt function

int crcInt(
  1. String data, [
  2. int? crc
])

CRC32 Copyright (C) 2012, Kai Sellgren Licensed under the MIT License. http://www.opensource.org/licenses/mit-license.php

Converted to dart code by chengfubeiming@live.com

Computes a CRC32 value for the given input.

The return value is an unsigned integer.

You may optionally specify the beginning CRC value.

Implementation

int crcInt(String data, [int? crc]) {
  crc ??= 0;
  final input = utf8.encode(data);

  var checksum = crc ^ (0xffffffff);

  for (var byte in input) {
    var x = _table[(checksum ^ byte) & 0xff];
    checksum =
        (checksum & 0xffffffff) >> 8; // crc >>> 8 (32-bit unsigned integer)
    checksum ^= x;
  }

  checksum = checksum ^ (0xffffffff);

  // Turns the signed integer into an unsigned integer.
  return checksum & 0xffffffff;
}