/**********************************************************************
* Function : Fletcher16
* Description : Calculate Fletcher16
*
* Return:
*
**********************************************************************/
Uint16 Fletcher16(Uint16 *data,Uint16 count)
{
Uint16 sum1 = 0xFF;
Uint16 sum2 = 0xFF;
Uint16 tlen;
while(count){
tlen = count >=20? 20:count;
count-=tlen;
do{
sum2+=sum1+=*data++;
}while(--tlen);
sum1 = (sum1 & 0xFF) + (sum1 >> 8);
sum2 = (sum2 & 0xFF) + (sum2 >> 8);
}
//Second reduction step to reduce sums to 8 bits
sum1 = (sum1 & 0xFF) + (sum1 >> 8);
sum2 = (sum2 & 0xFF) + (sum2 >> 8);
return sum2 << 8 | sum1;
}
Fletcher16校验算法
最新推荐文章于 2024-08-06 10:48:10 发布