Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void crc(unsigned char msgData[],byte *lowbyte,byte *highbyte)
- {
- unsigned short Polynom = 0x8408;
- unsigned short Register = 0x0000;
- unsigned short temp = 0x0000;
- // loop through the entire array of bytes
- for( int i = 0; i < sizeof(msgData); i++ )
- {
- temp = msgData[i];
- // shift all 8 data bits once
- for( int y = 0; y < 8; y++ )
- {
- if ( ( ( Register ^ temp ) & 0x01 ) == 0x01 )
- {
- Register >>= 1;
- Register ^= Polynom;
- }
- else
- {
- Register >>= 1;
- }
- temp >>= 1; // shift data 1 bit right, dividing it by 2
- } // end of inner for loop (bit shift loop)
- } // end of outer for loop (data loop)
- // now we have got our overall 2-byte CRC "Checksum" number
- *lowbyte = (byte) ( Register / 256 );
- *highbyte = (byte) ( Register % 256 );
- }
Add Comment
Please, Sign In to add comment