Generates a 16-bit CRC-CCITT checksum.
This is a table based 16-bit CRC popular for modem protocols defined for use by the Consultative Committee on International Telegraphy and Telephony (CCITT)
Beispiel #1
0
        /// <summary>Calculates the CRC-CCITT 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-CCITT checksum over the specified portion of the buffer.</returns>
        /// <remarks>
        /// The CRC-CCITT is a table based 16-bit CRC popular for modem protocols defined for use by the
        /// Consultative Committee on International Telegraphy and Telephony (CCITT)
        /// </remarks>
        public static ushort CrcCCITTChecksum(this byte[] data, int startIndex, int length)
        {
            CrcCCITT checksum = new CrcCCITT();

            checksum.Update(data, startIndex, length);

            return(checksum.Value);
        }
Beispiel #2
0
        public void UpdateByteTest()
        {
            CrcCCITT checksum = new CrcCCITT();

            foreach (byte d in SampleData)
                checksum.Update(d);

            Assert.AreEqual(SampleDataChecksum, checksum.Value);
        }
Beispiel #3
0
        public void MixedUpdateTest()
        {
            CrcCCITT checksum = new CrcCCITT();
            int i = 0;

            checksum.Reset();

            while (i < SampleData.Length / 4)
                checksum.Update(SampleData[i++]);

            for (int j = 0; j < 2; j++)
            {
                checksum.Update(SampleData, i, SampleData.Length / 4);
                i += SampleData.Length / 4;
            }

            while (i < SampleData.Length)
                checksum.Update(SampleData[i++]);

            Assert.AreEqual(SampleDataChecksum, checksum.Value);
        }
Beispiel #4
0
        /// <summary>Calculates the CRC-CCITT 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-CCITT checksum over the specified portion of the buffer.</returns>
        /// <remarks>
        /// The CRC-CCITT is a table based 16-bit CRC popular for modem protocols defined for use by the
        /// Consultative Committee on International Telegraphy and Telephony (CCITT) 
        /// </remarks>
        public static ushort CrcCCITTChecksum(this byte[] data, int startIndex, int length)
        {
            CrcCCITT checksum = new CrcCCITT();

            checksum.Update(data, startIndex, length);

            return checksum.Value;
        }