Implementation of CRC16 using polynomial 0x8005 - (X^16+X^15+X^2+1)
cyclic redundancy check
A cyclic redundancy check (CRC) is an error-detecting code commonly used in digital networks and storage devices to detect accidental changes to raw data. Blocks of data entering these systems get a short check value attached, based on the remainder of a polynomial division of their contents; on retrieval the calculation is repeated, and corrective action can be taken against presumed data corruption if the check values do not match.
[source:http://en.wikipedia.org/wiki/Cyclic_redundancy_check]
This class implements a basic CRC16 (17Bits) using polynomial 0x8005 (X^16 + X^15 + X^2 +1).
How to use this library
basic use of CRC 16t
char testdata[]= "123456789"; CRC16 *myCRC = new CRC16(); unsigned short resultCRC = myCRC->calculateCRC16(testdata,9); //9 is the length of the character array // pc.printf("%x",resultCRC);
CRC16.h@0:585ead300cab, 2014-02-12 (annotated)
- Committer:
- EmLa
- Date:
- Wed Feb 12 21:34:53 2014 +0000
- Revision:
- 0:585ead300cab
CRC16 implementation; 123456789 --> 0xFEE8
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
EmLa | 0:585ead300cab | 1 | #ifndef CRC16_H |
EmLa | 0:585ead300cab | 2 | #define CRC16_H |
EmLa | 0:585ead300cab | 3 | |
EmLa | 0:585ead300cab | 4 | class CRC16 |
EmLa | 0:585ead300cab | 5 | { |
EmLa | 0:585ead300cab | 6 | private: |
EmLa | 0:585ead300cab | 7 | const unsigned int SHIFTER = 0x00FF; |
EmLa | 0:585ead300cab | 8 | unsigned short crc16table[256]; |
EmLa | 0:585ead300cab | 9 | |
EmLa | 0:585ead300cab | 10 | public: |
EmLa | 0:585ead300cab | 11 | unsigned short calculateCRC16(char input[], int lenght); |
EmLa | 0:585ead300cab | 12 | CRC16(); |
EmLa | 0:585ead300cab | 13 | ~CRC16(); |
EmLa | 0:585ead300cab | 14 | }; |
EmLa | 0:585ead300cab | 15 | #endif |