public GeneralCRC(CrcArgument argument) { _crcArg = argument ?? throw new ArgumentNullException(nameof(argument)); if (_crcArg.Width > 64) { throw new ArgumentOutOfRangeException($"{nameof(argument)}.{nameof(argument.Width)}", argument.Width, "Only support under 64 bit!"); } //查表法 _crcTable = CreateTable(_crcArg.Width, _crcArg.Polynomial, _crcArg.ReflectIn); _rightShift = _crcArg.Width - (_crcArg.Width < 8 ? 1 : 8); _initValue = _crcArg.ReflectIn ? ReverseBits(_crcArg.InitValue, _crcArg.Width) : _crcArg.InitValue; }
/// <summary> /// 获取指定参数对应的CRC算法 /// </summary> /// <param name="argument">crc参数</param> public static ICrc GetCrc(CrcArgument argument) { return(new GeneralCRC(argument)); }