-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcrc.cpp
More file actions
51 lines (41 loc) · 1.16 KB
/
Copy pathcrc.cpp
File metadata and controls
51 lines (41 loc) · 1.16 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
#include <iostream>
#include <vector>
using namespace std;
int main(){
cout<<"Enter the Data to be sent: ";
string data;
cin>>data;
vector<int> binaryData;
vector<int> binaryDataCopy;
for (int i = 0; i < data.length(); ++i) {
binaryData.push_back(data[i] - '0');
binaryDataCopy.push_back(data[i] - '0');
}
cout<<"\nEnter the polynomial: ";
string poly;
cin>>poly;
vector<int> polyData;
for (int i = 0; i < poly.length(); ++i) {
polyData.push_back(poly[i] - '0');
}
int redundantBits = polyData.size()-1;
for (int i = 0; i < redundantBits; ++i) {
binaryDataCopy.push_back(0);
}
int j, k;
for (int i = 0; i < binaryData.size(); ++i) {
if(binaryDataCopy[i] >= polyData[0]){
for (int j = 0, k = i; j < polyData.size(); ++j, ++k) {
if(binaryDataCopy[k] == polyData[j]){
binaryDataCopy[k] = 0;
} else{
binaryDataCopy[k] = 1;
}
}
}
}
for (int i = 0; i < binaryDataCopy.size(); ++i) {
cout<<" "<<binaryDataCopy[i];
}
cout<<endl;
}