登录  注册 退出 English
鼎恩光彩{www.deanled.cn}
400-886-2386
  1. 首页 > 服务支持 > 二次开发

C#语言的CRC16校验算法

C#语言的CRC16校验算法:-------------------------------------------------------------------using Sy...
作者:小编 上传时间:2019-03-18 浏览量:621
文件下载列表 :
详细介绍

C#语言的CRC16校验算法:

-------------------------------------------------------------------

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace CRC16test

{

class Program

{

static int crc16 (byte [] data, int size)

{

int crc = 0x0;

byte data_t;

int i = 0;

int j = 0;

if (data == null)

{

return 0;

}

for (j = 0; j < size; j++)

{

data_t = data [j];

crc = (data_t ^ (crc));

for (i = 0; i < 8; i++)

{

if ( (crc & 0x1) == 1)

{

crc = (crc >> 1) ^ 0xA001;

}

else

{

crc >>= 1;

}

}

}

return crc;

}

static void Main (string [] args)

{

int CheckValue;

string str = String.Empty;

byte [] array = new byte [4]{0x33,0x20,0x9F,0xD5};

CheckValue = crc16 (array, array.Length);

str = ( (CheckValue >> 8) & 0xff).ToString ("X2").ToUpper ();

str += " "+ (CheckValue & 0xff).ToString ("X2").ToUpper ();

Console.WriteLine (str);

Console.ReadLine ();

}

}

}

-------------------------------------------------------


image.png


标签: C# CRC16
随便看看
18922864126
18922864126
已为您复制好微信号,点击进入微信