Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: CRC16_CCITT.cpp
- Revision:
- 1:6ecc3a64bf7b
- Parent:
- 0:253105d48c3c
--- a/CRC16_CCITT.cpp Sat Sep 02 08:26:22 2017 +0000
+++ b/CRC16_CCITT.cpp Sun Sep 03 08:29:38 2017 +0000
@@ -4,7 +4,7 @@
*
* Modified by Zoltan Hudak to implement CRC16-CCITT
* using the polynomial 0x1021: X^16 + X^15 + X^2 + 1.
- * Initial CRC register = 0x0000
+ * Default initial CRC value = 0x0000
*/
#include "CRC16_CCITT.h"
@@ -46,14 +46,15 @@
0x6E17, 0x7E36, 0x4E55, 0x5E74, 0x2E93, 0x3EB2, 0x0ED1, 0x1EF0
};
-unsigned short CRC16_CCITT::calc(char input[], int length) {
- unsigned short result = 0;
+unsigned short CRC16_CCITT::calc(char input[], int length, unsigned short crc /*=0x0000*/) {
for(int i = 0; i < length; i++) {
- unsigned short tableValue = TABLE[((result >> 8) ^ *(char*)input++) & SHIFTER];
- result = (result << 8) ^ tableValue;
+ unsigned short tableValue = TABLE[((crc >> 8) ^ *(char*)input++) & SHIFTER];
+ crc = (crc << 8) ^ tableValue;
}
- return result;
+ return crc;
}
+
+