AceCRC  0.3.1
Cyclic Redundancy Check (CRC) algorithms (e.g. crc32(), crc16ccitt()) programmatically converted from C99 code generated by pycrc (https://pycrc.org) to Arduino C++ using namespaces and PROGMEM flash memory.
crc16ccitt_bit.cpp
Go to the documentation of this file.
1 
20 #include "crc16ccitt_bit.hpp" // header file converted by AceCRC
21 #include <stdlib.h>
22 #include <stdint.h>
23 #include <stdbool.h>
24 
25 namespace ace_crc {
26 namespace crc16ccitt_bit {
27 
28 
29 
30 crc_t crc_update(crc_t crc, const void *data, size_t data_len)
31 {
32  const unsigned char *d = (const unsigned char *)data;
33  unsigned int i;
34  bool bit;
35  unsigned char c;
36 
37  while (data_len--) {
38  c = *d++;
39  for (i = 0x80; i > 0; i >>= 1) {
40  bit = crc & 0x8000;
41  if (c & i) {
42  bit = !bit;
43  }
44  crc <<= 1;
45  if (bit) {
46  crc ^= 0x1021;
47  }
48  }
49  crc &= 0xffff;
50  }
51  return crc & 0xffff;
52 }
53 
54 } // crc16ccitt_bit
55 } // ace_crc
crc16ccitt_bit.hpp
ace_crc::crc16ccitt_bit::crc_t
uint16_t crc_t
The type of the CRC values.
Definition: crc16ccitt_bit.hpp:68
ace_crc::crc16ccitt_bit::crc_update
crc_t crc_update(crc_t crc, const void *data, size_t data_len)
Update the crc value with new data.
Definition: crc16ccitt_bit.cpp:30