Generates a byte-wise 16-bit CRC calculation.

2-byte (16-bit) CRC: The generating polynomial is

16 15 2 1

G(X) = X + X + X + X

Exemple #1
0
		/// <summary>Calculates the CRC-ModBus check-sum on specified portion of a buffer.</summary>
		/// <param name="data">Data buffer to perform check-sum on.</param>
		/// <param name="startIndex">Starts index in data buffer to begin check-sum.</param>
		/// <param name="length">Total number of bytes from <paramref name="startIndex">startIndex</paramref> to
		/// perform check-sum over.</param>
		/// <returns>Computed CRC-ModBus checksum over the specified portion of the buffer.</returns>		
		public static ushort ModBusCrcChecksum(this byte[] data, int startIndex, int length)
		{
			Crc16 checksum = new Crc16(ChecksumType.ModBus);

			checksum.Update(data, startIndex, length);

			return checksum.Value;
		}
Exemple #2
0
        /// <summary>Calculates the CRC16 check-sum on specified portion of a buffer.</summary>
        /// <param name="data">Data buffer to perform check-sum on.</param>
        /// <param name="startIndex">Starts index in data buffer to begin check-sum.</param>
        /// <param name="length">Total number of bytes from <paramref name="startIndex">startIndex</paramref> to
        /// perform check-sum over.</param>
        /// <returns>Computed CRC16 checksum over the specified portion of the buffer.</returns>
        public static ushort Crc16Checksum(this byte[] data, int startIndex, int length)
        {
            Crc16 checksum = new Crc16();

            checksum.Update(data, startIndex, length);

            return checksum.Value;
        }