AceCRC
0.1
Cyclic Redundancy Check (CRC) algorithms (e.g. crc32(), crc16ccitt()) are progammatically converted from pycrc to Arduino C++, including variants (e.g. 4-bit versus 8-bit tables) that trade space and time.
src
ace_crc
crc32_bit.cpp
Go to the documentation of this file.
1
20
#include "
crc32_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
crc32_bit {
27
28
29
30
crc_t
crc_reflect
(
crc_t
data,
size_t
data_len)
31
{
32
unsigned
int
i;
33
crc_t
ret;
34
35
ret = data & 0x01;
36
for
(i = 1; i < data_len; i++) {
37
data >>= 1;
38
ret = (ret << 1) | (data & 0x01);
39
}
40
return
ret;
41
}
42
43
44
crc_t
crc_update(
crc_t
crc,
const
void
*data,
size_t
data_len)
45
{
46
const
unsigned
char
*d = (
const
unsigned
char
*)data;
47
unsigned
int
i;
48
bool
bit;
49
unsigned
char
c;
50
51
while
(data_len--) {
52
c = *d++;
53
for
(i = 0x01; i & 0xff; i <<= 1) {
54
bit = crc & 0x80000000;
55
if
(c & i) {
56
bit = !bit;
57
}
58
crc <<= 1;
59
if
(bit) {
60
crc ^= 0x04c11db7;
61
}
62
}
63
crc &= 0xffffffff;
64
}
65
return
crc & 0xffffffff;
66
}
67
68
}
// crc32_bit
69
}
// ace_crc
ace_crc::crc32_bit::crc_t
uint_fast32_t crc_t
The type of the CRC values.
Definition:
crc32_bit.hpp:68
crc32_bit.hpp
ace_crc::crc32_bit::crc_reflect
crc_t crc_reflect(crc_t data, size_t data_len)
Reflect all bits of a data word of data_len bytes.
Definition:
crc32_bit.cpp:30
Generated by
1.8.17