Click or drag to resize
Crc16Ccitt Class
A utility class that calculates CCITT-16 CRC values.
Inheritance Hierarchy
SystemObject
  VirtualRadar.InterfaceCrc16Ccitt

Namespace: VirtualRadar.Interface
Assembly: VirtualRadar.Interface (in VirtualRadar.Interface.dll) Version: 1.0.0.0 (1.0.0.0)
Syntax
public class Crc16Ccitt

The Crc16Ccitt type exposes the following members.

Constructors
  NameDescription
Public methodCrc16Ccitt
Creates a new object.
Top
Methods
  NameDescription
Public methodComputeChecksum(Byte)
Returns the CRC-16-CCITT checksum for the array of bytes passed across using the standard calculation.
Public methodComputeChecksum(Byte, Int32, Int32)
Returns the CRC-16-CCITT checksum for the array of bytes passed across using the standard calculation.
Public methodComputeChecksumBytes(Byte, Boolean)
Returns the CRC-16-CCITT checksum for the array of bytes passed across using the standard calculation.
Public methodComputeChecksumBytes(Byte, Int32, Int32, Boolean)
Returns the CRC-16-CCITT checksum for the array of bytes passed across using the standard calculation.
Public methodComputeChecksumDrDobbs
Returns the CRC-16-CCITT checksum for the array of bytes passed across using the Dr. Dobbs algorithm.
Public methodComputeChecksumDrDobbsBytes
Returns the CRC-16-CCITT checksum for the array of bytes passed across using the Dr. Dobbs algorithm.
Public methodEquals
Determines whether the specified Object is equal to the current Object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetHashCode
Serves as a hash function for a particular type.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Fields
  NameDescription
Public fieldStatic memberInitialiseToAllOnes
An initial CRC value of all-ones.
Public fieldStatic memberInitialiseToZero
An initial CRC value of zero.
Top
Remarks

Two algorithms were found that described themselves as CCITT-16 CRC calculators - the one that is used by Kinetic (and at least four other entities) and the one described in the Dr. Dobbs journal. The Dr. Dobbs one is included for the sake of completeness.

The Kinetic version was copied from the Sanity Free Coding blog - http://sanity-free.org/133/crc_16_ccitt_in_csharp.html. Note that the checksum that Kinetic use on SBS-3 packets is using an initial CRC value of zero. I modified the method that returns a byte array because Kinetic's CRC is sent big-endian and the original was returning it little-endian.

A second implementation of the standard algorithm was found here - http://www.ccsinfo.com/forum/viewtopic.php?t=24977. It purported to be faster than the lookup table version, which is probably true for implementations in hardware or languages that compile straight to assembly but was not found to be the case in testing under C#, it was marginally slower than Sanity Free Coding's implementation.

The Dr. Dobbs version was copied from the Dr. Dobbs journal site - http://www.drdobbs.com/implementing-the-ccitt-cyclical-redundan/199904926. The implementation here has been tested against the expected checksum in the examples listing on that page.

See Also