40 it_assert(
poly(0) == 1,
"CRC_Code::set_polynomial: not a valid polynomial");
42 no_parity = polynomial.size() - 1;
47 std::string crccode[18][2] = {
48 {
"CRC-4",
"1 1 1 1 1"},
49 {
"CRC-7",
"1 1 0 1 0 0 0 1"},
50 {
"CRC-8",
"1 1 1 0 1 0 1 0 1"},
51 {
"CRC-12",
"1 1 0 0 0 0 0 0 0 1 1 1 1"},
52 {
"CRC-24",
"1 1 0 0 0 0 0 0 0 0 1 0 1 0 0 0 1 0 0 0 0 0 0 0 1"},
53 {
"CRC-32",
"1 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 1 1 0 0 0 1 1 1 0 0 0 1 0"},
54 {
"CCITT-4",
"1 0 0 1 1"},
55 {
"CCITT-5",
"1 1 0 1 0 1"},
56 {
"CCITT-6",
"1 0 0 0 0 1 1"},
57 {
"CCITT-16",
"1 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 1"},
58 {
"CCITT-32",
"1 0 0 0 0 0 1 0 0 1 1 0 0 0 0 0 1 0 0 0 1 1 1 0 1 1 0 1 1 0 1 1 1"},
59 {
"WCDMA-8",
"1 1 0 0 1 1 0 1 1"},
60 {
"WCDMA-12",
"1 1 0 0 0 0 0 0 0 1 1 1 1"},
61 {
"WCDMA-16",
"1 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 1"},
62 {
"WCDMA-24",
"1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 1 1"},
63 {
"ATM-8",
"1 0 0 0 0 0 1 1 1"},
64 {
"ANSI-16",
"1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1"},
65 {
"SDLC-16",
"1 1 0 1 0 0 0 0 0 1 0 0 1 0 1 1 1"},
73 for (
int i = 0; i < 18;i++) {
74 if (crccode[i][0] == code)
75 poly = bvec(crccode[i][1]);
78 if ((code ==
"WCDMA-8") || (code ==
"WCDMA-12") || (code ==
"WCDMA-16") || (code ==
"WCDMA-24")) {
79 reverse_parity =
true;
82 it_assert(poly.size() > 0,
"This CRC code doesn't exist in the tables");
91 for (
int i = 0; i < temp.size() - polynomial.size() + 1; i++) {
93 temp.set_subvector(i, temp(i, i + no_parity) + polynomial);
97 out = temp(temp.size() - no_parity, temp.size() - 1);
108 int n = coded_bits.size();
111 if (reverse_parity) {
112 temp =
concat(coded_bits.left(n - no_parity),
reverse(coded_bits.right(no_parity)));
118 for (
int i = 0; i < temp.size() - polynomial.size() + 1; i++) {
120 temp.set_subvector(i, temp(i, i + no_parity) + polynomial);
124 if (temp(temp.size() - no_parity, temp.size() - 1) ==
zeros_b(no_parity))
146 out = coded_bits(0, coded_bits.size() - no_parity - 1);