Advertisement
Guest User

Untitled

a guest
Aug 17th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.49 KB | None | 0 0
  1. int checksum=0;
  2. int CrcReg=0;
  3. int BitPoint;
  4. for(int i=0; i<nbytes; ++i)
  5. {
  6.     BitPoint=128;
  7.     int Byte=a[i];
  8.    
  9.     int Poly;
  10.     for(int j=0; j<7; ++j)
  11.     {
  12.         if(BitPoint & Byte)
  13.         {
  14.             if(CrcReg & 0x80)Poly=1;
  15.             else Poly=28;
  16.             CrcReg<<=1;
  17.             CrcReg|=1;
  18.             CrcReg^=Poly;
  19.             CrcReg&=0xFF;
  20.         }
  21.         else
  22.         {
  23.             if(CrcReg & 0x80)Poly=29;
  24.             else Poly=0;
  25.             CrcReg<<=1;
  26.             CrcReg^=Poly;
  27.             CrcReg&=0xFF;
  28.         }
  29.         BitPoint>>=1;
  30.     }
  31.     checksum+=Byte;
  32.     checksum&=0xFF;
  33. }
  34. CRC=~CrcReg;
  35. CRC&=0xFF;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement