-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbitarraycrc.cpp
More file actions
71 lines (65 loc) · 2.23 KB
/
bitarraycrc.cpp
File metadata and controls
71 lines (65 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/***************************************************************************
* Arrays of Arbitrary Bit Length
*
* File : bitarraycrc.cpp
* Purpose :
*
* Author :
* Date :
*
****************************************************************************
* HISTORY
*
*
****************************************************************************
*
* <insert GNU license here>
*
***************************************************************************/
/***************************************************************************
* INCLUDED FILES
***************************************************************************/
#include <iostream>
#include <climits>
#include "bitarraycrc.h"
using namespace std;
/***************************************************************************
* MACROS
***************************************************************************/
/***************************************************************************
* METHODS
***************************************************************************/
/***************************************************************************
* Method :
* Description:
* Parameters :
* Effects :
* Returned :
***************************************************************************/
void
bit_array_crc(bit_array_c &crc,
const bit_array_c &input,
const bit_array_c &polynom,
const bit_array_c &code)
{
// TODO Check for Codelength and CRC Len to be polynomLen-1
// Concatenate input and code to be tested to a tmp bit array
bit_array_c tmp(input.Size()+crc.Size());
tmp.Copy(0, input, 0, input.Size());
tmp.Copy(input.Size(), code, 0, code.Size());
/* Step through input data
* if a bit is true, XOR the polynom to the tmp bit array
*/
for(unsigned int cnt=0; cnt<input.Size(); cnt++)
{
if(tmp[cnt])
{
for(unsigned int pos=0; pos<polynom.Size(); pos++)
{
tmp(cnt+pos) = tmp[cnt+pos] ^ polynom[pos];
}
}
}
// Copy to target BitArray
crc.Copy(0, tmp, input.Size(), crc.Size());
}