-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDriver.cpp
56 lines (55 loc) · 1.64 KB
/
Driver.cpp
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
#include <iostream>
#include <bitset>
#include "encoder.h"
#include "decoder.h"
#include <vector>
#include <string>
int main() {
std::cout << "\n [Binary Convolutional Code run ...]\n";
std::cout << " Errors and Error Correcting Codes\n";
std::cout << " e : encode || d : decode \n";
std::vector<bool> bits;
char bitInput;
bool encoderFlag = true;
std::cout << " select Encoder : e or Decoder : d :[default : encoder]: ";
std::cin >> bitInput;
bitInput = bitInput == 'd' ? encoderFlag = false : encoderFlag = true;
if (encoderFlag) {
std::cout << " f : end of stream || q : exit\n";
}
std::cout << std::endl << std::endl;
while (encoderFlag) {
std::cout << ">";
std::cin >> bitInput;
if (bitInput == 'q') {
exit(1);
}
if (bitInput == 'f') {
break;
}
if (bitInput != '0' && bitInput != '1') {
std::cout << "\n\n[Expected a binary sequence, found " << bitInput << "]" << std::endl;
exit(1);
}
bool bit = bitInput - '0';
bits.push_back(bit);
}
if (encoderFlag) {
encoder e = encoder();
for (int i = 0; i < bits.size(); i++) {
//e.encodeDetail(bool(stream[i] & 0x1));
e.encode(bits[i]);
}
}else {
std::cout << " example 0xHex :: D4 for 11010100" << std::endl;
std::cout << "enter 0xHEX value for Decodeing : ";
std::string str;
std::cin >> str;
int i = stoi(str, 0, 16);
decoder d = decoder();
d.decode(i & 0xFF);
}
// pause console
system("pause");
return 0;
}