CRC16算法实现(C语言)

CRC is short for Cyclic Redundancy Check.

A cyclic redundancy check (CRC) is a type of function that takes as input a data stream of any length and produces as output a value of a certain fixed size. The term CRC is often used to denote either the function or the function's output. A CRC can be used in the same way as a checksum to detect accidental alteration of data during transmission or storage. CRCs are popular because they are simple to implement in binary hardware, are easy to analyze mathematically, and are particularly good at detecting common errors caused by noise in transmission channels. The CRC was invented by W. Wesley Peterson, and published in his 1961 paper.

CRC的中文意思是循环冗余校验。

下面是CRC16的C语言实现:

int CRC16( char *p, int len )
{
   register unsigned char l, h, t;
   l=h=0xff;
   for( int i=0; i<len; i++ )
   {
      h^=p[i];
      h^=h>>4;
      t=h;
      h=l;
      l=t;
      t=(l<<4) | (l>>4);
      h^=((t<<2) | (t>>6)) & 0x1f;
      h^=t&0xf0;
      l^=((t<<1) | (t>>7)) & 0xe0;
   }
   return ((int)h<<8) | l;
}
 

The following link can help you getting detail information of CRC: http://en.wikipedia.org/wiki/Cyclic_redundancy_check

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值