Board logo

标题: CRC???é?÷??ר?ù-4 CRC???é???????ò?? [打印本页]

作者: zona    时间: 2004-5-21 22:55     标题: CRC???é?÷??ר?ù-4 CRC???é???????ò??

CRC???é???????ò??

????

?????????????????¨???ì?ò??????±??¤?????????·???????????????ì?í?????????????à?ì?í????????CRC??×?????????????CRC???????????·???à???é??????????:?ì?í?????????????ú?????×????±à???÷?°?ì?????·???????????ì?í???????????ü?ù????·??????í?ó??????????0.0047%???????????????????ú?????????ù???????????????é?°?????????é??·??????ò?????????????????????¨???ì?ò??CRC????????:???????¨?????éX.25??FCS(???ì?í?ò??)????????CRC-CCITT??ARJ??LHA???????¤???í??????????CRC32???????????÷????????????CRC16???¨????????????????GIF??TIFF????????CRC×÷???ì?í??????
CRC??±???????-2??·¨???à????????????????????CRC???à???????????ù???¨????CRC?????????ú???à??????±í????×???????CRC?????ú???à??????±í1?ù????
@@10A08800.GIF;±í1.×???????CRC???°?ú???à????@@
????CRC???¨???????????í?í??????????????±??????????¤×÷????????·¨????????????±?????×??á??±à????????????×????§????CRC?¨?????ò?????????ò?????é±í·¨????CRC????????????????°????±????·?????????·¨?????????????¨???????????????ò??
?¨????CRC??·¨??????????????????CRC???±????CRC???????ó????????????CRC????????CRC?????÷????·????ü???????????????ù???ó??CRC?????????????¨????CRC??·¨????????????·???:????8??????????16???????÷???????????????÷????8???ò??8?????????à×÷???????á??????256????????×é???????ò???????????????é±í·¨???ú??·??????????????????ù??????CRC32????????±????ù?á???????ò??????????crchware????°???16??CRC????·¨??mk-crctbl?????????????¨??????CRC????±í??crcupdate?????é±í???ü??CRC?????÷??????crcrevhware??crcrevupdate??·??ò??·¨????????????BuildCRCTable??CalculateBlockCRC32??UpdateCharac
terCRC32????CRC32????????
/* CRC.C????CRC???ò?? */
#define CRCCCITT 0x1021
#define CCITT-REV 0x8408
#define CRC16 0x8005
#define CRC16-REV 0xA001
#define CRC32-POLYNOMIAL 0xEDB88320L
/* ??????CRC???????¨?? */
#define NIL 0
#define crcupdate(d,a,t)*(a)=(*(a)<<8)^(t)[(*(a)>>8)^(d)];
#define crcupdate16(d,a,t)*(a)=(*(a)>>8^(t)[(*(a)^(d))&0x00ff])
/* ?????????ê?????ú??????crcupdate??crcrevupdate */
#include<stdio.h>
#include<stdlib.h>
#include<alloc.h>
/* ????crchware????????CRC??·¨????·???????CRC?? */
unsigned short crchware(data,genpoly,accum)
unsigned short data;/* ?????????? */
unsigned short genpoly;/* CRC???? */
unsigned short accum;/* CRC?????÷?? */
{
static int i;
data<<=8;
for(i=8;i>0;i--)
{
if((data^accum)&0x8000)
accum=(accum<<1)^genpoly;
else
accum<<=1;
data<<=1;
}
return (accum);
}
/* ????mk-crctbl????????crchware?¨??????????CRC????±í */
unsigned short *mk-crctbl(poly,crcfn);
unsigned short poly;/* CRC????--CRC?ú???à???? */
unsigned short (*crcfn)();/* ???òCRC????(????crchware)?????? */
{
/* unsigned short */malloc(); */
unsigned short *crctp;
int i;
if((crctp=(unsigned short*)malloc(256*sizeof(unsigned)))==0)
return 0;
for(i=0;i<256;i++)
crctp=(*crcfn)(i,poly,0);
return crctp;
}
/* ????mk-crctbl??????·??? */
if((crctblp=mk-crctbl(CRCCCITT,crchware))==NIL)
{
puts("insuff memory for CRC lookup table.n";
return 1; */
/* ????crcupdate???????é±í·¨????CRC?????ü??CRC?????÷?? */
void crcupdate(data,accum,crctab)
unsigned short data;/* ?????????? */
unsigned short *accum;/* ???òCRC?????÷?????? */
unsigned short *crctab;/* ???ò??????CRC±í?????? */
{
static short comb-val;
comb-val=(*accum>>8)^data;
*accum=(*accum<<8)^crctab[comb-val];
}
/* ????crcrevhware????????CRC??·¨??·??ò??·¨????·???????CRC?? */
unsigned short crcrevhware(data,genpoly,accum)
unsigned short data;
unsigned short genpoly;
unsigned short accum;
{
static int i;
data<<=1;
for(i=8;i>0;i--)
{
data>>=1;
if((data^accum)&0x0001)
accum=(accum>>1)^genpoly;
else
accum>>=1;
}
return accum;
}
/* ????crcrevupdate??????·??ò?é±í·¨????CRC?????ü??CRC?????÷?? */
void crcrevupdate(data,accum,crcrevtab)
unsigned short data;
unsigned short *accum;





欢迎光临 我要委托设计网论坛 (http://51odm.com/fourms/) Powered by Discuz! 5.5.0