-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
104 lines (81 loc) · 3.32 KB
/
Copy pathmain.cpp
File metadata and controls
104 lines (81 loc) · 3.32 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include "correct.h"
#include <iostream>
using namespace std;
int main() {
// This section illustrates the use of the pre-supplied helper functions
cout << "================== Helper functions ====================" << endl
<< endl;
char binary[9];
ascii_to_binary('A', binary);
cout << "The ASCII code of 'A' is " << int('A') << " which in binary is "
<< binary << endl;
ascii_to_binary('r', binary);
cout << "The ASCII code of 'r' is " << int('r') << " which in binary is "
<< binary << endl;
ascii_to_binary('t', binary);
cout << "The ASCII code of 't' is " << int('t') << " which in binary is "
<< binary << endl
<< endl;
char ch;
ch = binary_to_ascii("01000001");
cout << "The character correspoding to the binary number 01000001 is '"
<< ch << "'" << endl
<< endl;
cout << "====================== Question 1 ======================" << endl
<< endl;
char encoded[512], text[32];
text_to_binary("Art", encoded);
cout << "'Art' encoded as binary is " << encoded << endl << endl;
binary_to_text("010000010111001001110100", text);
cout << "010000010111001001110100 decoded as text is '" << text << "'"
<< endl
<< endl;
cout << "====================== Question 2 ======================" << endl
<< endl;
char correct[512];
add_error_correction("0100", correct);
cout << "0100"
<< " with error correction bits inserted is: " << endl
<< correct << endl
<< endl;
add_error_correction("01000001", correct);
cout << "01000001"
<< " with error correction bits inserted is: " << endl
<< correct << endl
<< endl;
add_error_correction("010000010111001001110100", correct);
cout << "010000010111001001110100 with error correction bits inserted is: "
<< endl
<< correct << endl
<< endl;
cout << "====================== Question 3 ======================" << endl
<< endl;
char decoded[512];
int errors = 0;
strcpy(correct, "1001100");
errors = decode(correct, decoded);
cout << correct << " decoded is " << decoded << " (" << errors
<< " errors corrected)" << endl
<< endl;
strcpy(correct, "1001110");
errors = decode(correct, decoded);
cout << correct << " decoded is " << decoded << " (" << errors
<< " errors corrected)" << endl
<< endl;
strcpy(correct, "100111011010010001110010101000011011001100");
errors = decode(correct, decoded);
cout << correct << " decoded is:" << endl
<< decoded << " (" << errors << " errors corrected)" << endl;
binary_to_text(decoded, text);
cout << "which as text is '" << text << "'" << endl << endl;
strcpy(correct, "0001100000100101000100000100110011001101001110110111111000"
"0101111001101100110010010101010100000000100110010000110101"
"010011001101010100110011");
errors = decode(correct, decoded);
cout << correct << " decoded is:" << endl
<< decoded << " (" << errors << " errors corrected)" << endl;
binary_to_text(decoded, text);
cout << "which as text is '" << text << "'" << endl << endl;
cout << "======================= The End ========================" << endl
<< endl;
}