C#实现CRC16校验码计算示例

遇到需要进行CRC校验时,经过翻阅大量资料后终于理解了CRC16的计算原理。这里提供了详细注释,使用的不是普通的词典法,而是通过算法计算得出的CRC值。对于CRC16-CCITT,只需按照给定的公式进行替换即可。具体实现原理如下:

1. 首先将16位CRC寄存器CRCFull初始化为全1
2. 对于数据message[i]的每一个字节(8位),与CRCFull进行异或操作,并将结果存入CRCFull中
3. 将CRCFull的最低位作为CRCLSB,然后将CRCFull右移一位(向低位),并用0填补最高位
4. 检查CRCLSB的原最低位:如果为1,则与多项式0xA001进行异或操作;如果为0,则重复上一步
5. 重复上述步骤直到右移8次,处理完整个message[i]字节
6. 继续重复上述步骤,处理下一个字节的8位数据,直到处理完整个message[i]
7. 最终得到的CRC寄存器CRCFull即为该数据的CRC16校验码

rar
WindowsFormsApplication1.rar 预估大小:26个文件
folder
WindowsFormsApplication1 文件夹
folder
WindowsFormsApplication1 文件夹
folder
bin 文件夹
folder
Debug 文件夹
file
WindowsFormsApplication1.pdb 28KB
file
WindowsFormsApplication1.vshost.exe.manifest 490B
file
WindowsFormsApplication1.vshost.exe 11KB
file
WindowsFormsApplication1.exe 10KB
file
Form1.Designer.cs 3KB
file
Program.cs 505B
folder
obj 文件夹
folder
x86 文件夹
folder
Debug 文件夹
file
WindowsFormsApplication1.pdb 28KB
file
GenerateResource.write.1.tlog 1KB
file
WindowsFormsApplication1.csproj.FileListAbsolute.txt 2KB
file
WindowsFormsApplication1.Properties.Resources.resources 180B
file
DesignTimeResolveAssemblyReferencesInput.cache 6KB
file
ResolveAssemblyReference.cache 8KB
file
DesignTimeResolveAssemblyReferences.cache 4KB
file
GenerateResource.read.1.tlog 608B
folder
TempPE 文件夹
file
WindowsFormsApplication1.exe 10KB
file
WindowsFormsApplication1.Form1.resources 180B
file
Form1.cs 3KB
file
Form1.resx 6KB
file
WindowsFormsApplication1.csproj 4KB
folder
Properties 文件夹
file
Resources.resx 5KB
file
Settings.settings 249B
file
AssemblyInfo.cs 1KB
file
Settings.Designer.cs 1KB
file
Resources.Designer.cs 3KB
file
WindowsFormsApplication1.sln 914B
file
WindowsFormsApplication1.suo 21KB
rar 文件大小:42.8KB