Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int checksum=0;
- int CrcReg=0;
- int BitPoint;
- for(int i=0; i<nbytes; ++i)
- {
- BitPoint=128;
- int Byte=a[i];
- int Poly;
- for(int j=0; j<7; ++j)
- {
- if(BitPoint & Byte)
- {
- if(CrcReg & 0x80)Poly=1;
- else Poly=28;
- CrcReg<<=1;
- CrcReg|=1;
- CrcReg^=Poly;
- CrcReg&=0xFF;
- }
- else
- {
- if(CrcReg & 0x80)Poly=29;
- else Poly=0;
- CrcReg<<=1;
- CrcReg^=Poly;
- CrcReg&=0xFF;
- }
- BitPoint>>=1;
- }
- checksum+=Byte;
- checksum&=0xFF;
- }
- CRC=~CrcReg;
- CRC&=0xFF;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement