CRC12检验DELPHI源码

先是单片机编译器上的C源码
#include <reg52.h>
unsigned char exz[4]={0x31,0x30,0x34,0x32};
unsigned int crc;
unsigned int CRC12(unsigned char *ptr,unsigned char len)
{
    unsigned char i;
    unsigned char j;
    j = 0;
    while(len)
    {
        /*多项式除法*/
        if(*ptr & (0x80>>j))  //如果该位为1
            crc |= 0x01;  //则在余数尾部添1否则添0 |=相当于CRC=CRC或0x01 或算法
        if(crc >= 0x1000)
            crc ^= 0x180D; //^=是异或
        crc <<= 1;
        j++;
        if(j == 8)
        {
            j = 0;
            ptr++;
            len--;
        }
    }
    /*对后面添加的12个0做处理*/
    for(i=0; i<12; i++)
    {
        if(crc >= 0x1000)
            crc ^= 0x180D;
        crc <<= 1;
    }
    crc >>= 1;
    return(crc);
}
void main(void)
{
   unsigned int cc;
   cc=CRC12(exz,4);
   while(1);
}  

你可能感兴趣的:(CRC12检验DELPHI源码)