예제 #1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="type">位数</param>
 /// <param name="initialValue">初始值</param>
 public CrcCcitt(CrcType type, InitialCrcValue initialValue = InitialCrcValue.Zeros)
 {
     crcType = type;
     if (crcType == CrcType.CRC_16)
     {
         initialCrcValue   = initialValue;
         this.initialValue = (ushort)initialValue;
         ushort temp, a;
         for (int i = 0; i < table.Length; i++)
         {
             temp = 0;
             a    = (ushort)(i << 8);
             for (int j = 0; j < 8; j++)
             {
                 if (((temp ^ a) & 0x8000) != 0)
                 {
                     temp = (ushort)((temp << 1) ^ polynominal);
                 }
                 else
                 {
                     temp <<= 1;
                 }
                 a <<= 1;
             }
             table[i] = temp;
         }
     }
 }
예제 #2
0
 public static extern short TMCRC(short length, byte[] data, ushort seed, CrcType type);
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            CrcType crc = (CrcType)value;

            return(crc.GetDisplayName());
        }