Fletcher16校验算法

/**********************************************************************
* 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;
}

你可能感兴趣的:(c/c++)