Gapotchenko.FX.Data.Integrity.Checksum.Crc16
2024.1.3
Prefix Reserved
dotnet add package Gapotchenko.FX.Data.Integrity.Checksum.Crc16 --version 2024.1.3
NuGet\Install-Package Gapotchenko.FX.Data.Integrity.Checksum.Crc16 -Version 2024.1.3
<PackageReference Include="Gapotchenko.FX.Data.Integrity.Checksum.Crc16" Version="2024.1.3" />
paket add Gapotchenko.FX.Data.Integrity.Checksum.Crc16 --version 2024.1.3
#r "nuget: Gapotchenko.FX.Data.Integrity.Checksum.Crc16, 2024.1.3"
// Install Gapotchenko.FX.Data.Integrity.Checksum.Crc16 as a Cake Addin #addin nuget:?package=Gapotchenko.FX.Data.Integrity.Checksum.Crc16&version=2024.1.3 // Install Gapotchenko.FX.Data.Integrity.Checksum.Crc16 as a Cake Tool #tool nuget:?package=Gapotchenko.FX.Data.Integrity.Checksum.Crc16&version=2024.1.3
Overview
The module provides the implementation of checksum algorithms belonging to the CRC-16 family.
Quick Start
Use the following code to calculate a CRC-16 checksum for the specified data, be it System.Byte[]
, System.ReadOnlySpan<Byte>
or System.IO.Stream
:
using Gapotchenko.FX.Data.Integrity.Checksum;
var checksum = Crc16.Standard.ComputeChecksum(data);
If you need to calculate a CRC-16 checksum iteratively then the following approach becomes handy:
var iterator = Crc16.Standard.CreateIterator();
iterator.ComputeBlock(...); // block 1
// ...
iterator.ComputeBlock(...); // block N
// Compute the final checksum:
var checksum = iterator.ComputeFinal();
Available CRC-16 Algorithms
CRC-16 family of cyclic redundancy checks consists of several attested checksum algorithms with predefined parameters:
Algorithm | Aliases | Gapotchenko.FX Implementation | Parameters: poly | init | refin | refout | xorout | check |
---|---|---|---|---|---|---|---|---|
CRC-16 (standard, recommended) | CRC-16/ARC, CRC-IBM, CRC-16/LHA | Crc16.Standard |
0x8005 | 0x0000 | true | true | 0x0000 | 0xbb3d |
CRC-16/CCITT | CRC-16/KERMIT, CRC-16/CCITT-TRUE, CRC-16/V-41-LSB, CRC-CCITT, KERMIT | Crc16.Attested.Ccitt |
0x1021 | 0x0000 | true | true | 0x0000 | 0x2189 |
CRC-16/ISO-IEC-14443-3-A | CRC-A | Crc16.Attested.IsoIec14443_3_A |
0x1021 | 0xc6c6 | true | true | 0x0000 | 0xbf05 |
CRC-16/ISO-IEC-14443-3-B | CRC-B, CRC-16/IBM-SDLC, CRC-16/ISO-HDLC, CRC-16/X-25, X-25 | Crc16.Attested.IsoIec14443_3_B |
0x1021 | 0xffff | true | true | 0xffff | 0x906e |
CRC-16/NRSC-5 | Crc16.Attested.Nrsc5 |
0x080b | 0xffff | true | true | 0x0000 | 0xa066 | |
CRC-16/MAXIM | CRC-16/MAXIM-DOW | Crc16.Attested.Maxim |
0x8005 | 0x0000 | true | true | 0xffff | 0x44c2 |
CRC-16/SPI-FUJITSU | CRC-16/AUG-CCITT | Crc16.Attested.SpiFujitsu |
0x1021 | 0x1d0f | false | false | 0x0000 | 0xe5cc |
CRC-16/UMTS | CRC-16/VERIFONE, CRC-16/BUYPASS | Crc16.Attested.Umts |
0x8005 | 0x0000 | false | false | 0x0000 | 0xfee8 |
CRC-16/USB | Crc16.Attested.Usb |
0x8005 | 0xffff | true | true | 0xffff | 0xb4c8 | |
CRC-16/XMODEM | CRC-16/ACORN, CRC-16/LTE, CRC-16/V-41-MSB, XMODEM, ZMODEM | Crc16.Attested.XModem |
0x1021 | 0x0000 | false | false | 0x0000 | 0x31c3 |
CRC-16/PROFIBUS | CRC-16/IEC-61158-2 | Crc16.Attested.Profibus |
0x1dcf | 0xffff | false | false | 0xffff | 0xa819 |
CRC-16/MODBUS | MODBUS | Crc16.Attested.Modbus |
0x8005 | 0xffff | true | true | 0x0000 | 0x4b37 |
CRC-16/GENIBUS | CRC-16/DARC, CRC-16/EPC, CRC-16/EPC-C1G2, CRC-16/I-CODE | Crc16.Attested.Genibus |
0x1021 | 0xffff | false | false | 0xffff | 0xd64e |
CRC-16/GSM | Crc16.Attested.Gsm |
0x1021 | 0x0000 | false | false | 0xffff | 0xce3c | |
CRC-16/OPENSAFETY-A | Crc16.Attested.OpenSafetyA |
0x5935 | 0x0000 | false | false | 0x0000 | 0x5d38 | |
CRC-16/OPENSAFETY-B | Crc16.Attested.OpenSafetyB |
0x755b | 0x0000 | false | false | 0x0000 | 0x20fe | |
CRC-16/TMS37157 | Crc16.Attested.TMS37157 |
0x1021 | 0x89ec | true | true | 0x0000 | 0x26b1 | |
CRC-16/MCRF4XX | Crc16.Attested.MCRF4xx |
0x1021 | 0xffff | true | true | 0x0000 | 0x6f91 | |
CRC-16/DECT-R | R-CRC-16 | Crc16.Attested.DectR |
0x0589 | 0x0000 | false | false | 0x0001 | 0x007e |
CRC-16/DECT-X | X-CRC-16 | Crc16.Attested.DectX |
0x0589 | 0x0000 | false | false | 0x0000 | 0x007f |
CRC-16/DDS-110 | Crc16.Attested.Dds110 |
0x8005 | 0x800d | false | false | 0x0000 | 0x9ecf | |
CRC-16/CCITT-FALSE | CRC-16/AUTOSAR, CRC-16/IBM-3740 | Crc16.Attested.CcittFalse |
0x1021 | 0xffff | false | false | 0x0000 | 0x29b1 |
The check
parameter shows what checksum value an algorithm should produce for "123456789"
input string interpreted as an ASCII data:
// Get the byte representation of the ASCII string.
var data = Encoding.ASCII.GetBytes("123456789");
// Compute the checksum.
var checksum = Crc16.Standard.ComputeChecksum(data);
// Print out the result ("Checksum=0xbb3d" for standard CRC-16).
Console.WriteLine("Checksum=0x{0:x}", checksum);
Recommended CRC-16 Algorithm
Among all other possibilities, it is recommended to use the standard CRC-16 algorithm which comes under CRC-16, CRC-16/ARC, CRC-IBM, CRC-16/LHA aliases and is available via Crc16.Standard
property.
All other predefined algorithms are available via the corresponding properties of Crc16.Attested
class.
Custom CRC-16 Algorithms
Once in a while, you may encounter a custom CRC-16 algorithm that is neither widely known nor characterized. In that case, you can instantiate a custom checksum algorithm with the desired parameters by hand:
var checksumAlgorithm = new CustomCrc16(poly, init, refin, refout, xorout);
If you want to formalize the custom algorithm even further, you may opt in to create a separate class for it with a convenient accessor property:
/// <summary>
/// Defines a custom CRC-16 algorithm.
/// </summary>
sealed class FooCrc16 : CustomCrc16
{
FooCrc16() :
base(poly, init, refin, refout, xorout)
{
}
public static FooCrc16 Instance { get; } = new();
}
That will allow you to use the algorithm effortlessly from several places in the codebase later:
var checksum = FooCrc16.Instance.ComputeChecksum(...);
Commonly Used Types
Gapotchenko.FX.Data.Integrity.Checksum.Crc16
Other Modules
Let's continue with a look at some other modules provided by Gapotchenko.FX:
- Gapotchenko.FX
- Gapotchenko.FX.AppModel.Information
- Gapotchenko.FX.Collections
- Gapotchenko.FX.Console
- Gapotchenko.FX.Data
- Gapotchenko.FX.Diagnostics
- Gapotchenko.FX.IO
- Gapotchenko.FX.Linq
- Gapotchenko.FX.Math
- Gapotchenko.FX.Memory
- Gapotchenko.FX.Security.Cryptography
- Gapotchenko.FX.Text
- Gapotchenko.FX.Threading
- Gapotchenko.FX.Tuples
Or look at the full list of modules.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 is compatible. netcoreapp2.2 was computed. netcoreapp3.0 is compatible. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
.NET Framework | net461 is compatible. net462 was computed. net463 was computed. net47 was computed. net471 is compatible. net472 is compatible. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETCoreApp 2.1
- Gapotchenko.FX.Data.Integrity.Checksum (>= 2024.1.3)
- Gapotchenko.FX.Numerics (>= 2024.1.3)
-
.NETCoreApp 3.0
- Gapotchenko.FX.Data.Integrity.Checksum (>= 2024.1.3)
- Gapotchenko.FX.Numerics (>= 2024.1.3)
-
.NETFramework 4.6.1
- Gapotchenko.FX.Data.Integrity.Checksum (>= 2024.1.3)
- Gapotchenko.FX.Numerics (>= 2024.1.3)
- System.ValueTuple (>= 4.5.0)
-
.NETFramework 4.7.1
- Gapotchenko.FX.Data.Integrity.Checksum (>= 2024.1.3)
- Gapotchenko.FX.Numerics (>= 2024.1.3)
-
.NETFramework 4.7.2
- Gapotchenko.FX.Data.Integrity.Checksum (>= 2024.1.3)
- Gapotchenko.FX.Numerics (>= 2024.1.3)
-
.NETStandard 2.0
- Gapotchenko.FX.Data.Integrity.Checksum (>= 2024.1.3)
- Gapotchenko.FX.Numerics (>= 2024.1.3)
-
.NETStandard 2.1
- Gapotchenko.FX.Data.Integrity.Checksum (>= 2024.1.3)
- Gapotchenko.FX.Numerics (>= 2024.1.3)
-
net5.0
- Gapotchenko.FX.Data.Integrity.Checksum (>= 2024.1.3)
- Gapotchenko.FX.Numerics (>= 2024.1.3)
-
net6.0
- Gapotchenko.FX.Data.Integrity.Checksum (>= 2024.1.3)
- Gapotchenko.FX.Numerics (>= 2024.1.3)
-
net7.0
- Gapotchenko.FX.Data.Integrity.Checksum (>= 2024.1.3)
- Gapotchenko.FX.Numerics (>= 2024.1.3)
-
net8.0
- Gapotchenko.FX.Data.Integrity.Checksum (>= 2024.1.3)
- Gapotchenko.FX.Numerics (>= 2024.1.3)
-
net9.0
- Gapotchenko.FX.Data.Integrity.Checksum (>= 2024.1.3)
- Gapotchenko.FX.Numerics (>= 2024.1.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.