-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
63 lines (57 loc) · 1.52 KB
/
main.cpp
File metadata and controls
63 lines (57 loc) · 1.52 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
#include "big_integer_1_a.h"
#include <ctime>
int main()
{
char * digitString0 = "1000000000065445677799800000000000000000000000"; // 4294967296
clock_t clock1, clock2;
//clock1 = clock();
BigInt d1(digitString0);
BigInt d2;
d2 = "1000000000000000000543211460000000000";
BigInt d3;
d3 = d1 + d2;
std::cout << d1 << "\n+\n";
std::cout << d2 << "\n=\n";
std::cout << "d3:\n";
std::cout << "Decimal number: \n";
std::cout << d3 << std::endl;
std::cout << "Binary number: \n";
d3.PrintBits();
std::cout << "Number of bits: \n";
std::cout << BigInt::getNumBits(d3.getBinarySet());
std::cout << std::endl;
// Checking the bit
std::cout << "\nEnter position to check bit, or press 0 to continue!\n";
while (true)
{
int pos;
std::cout << "Pos: ";
std::cin >> pos;
if (std::cin.fail())
{
std::cout << "Invalid data type!\n";
std::cin.clear();
std::cin.ignore(999, '\n');
continue;
}
if (pos == 0)
break;
bool boolBit;
try
{
boolBit = d3.getBit(pos);
}
catch (const char * e)
{
std::cout << e << std::endl;
continue;
}
std::cout << "Bit is: " << boolBit << "\n";
}
// Setting the bit
d3.setBit(3, true);
assert(d3.getBit(3));
std::cout << "\nBinary number after setting a bit to position 3: \n";
d3.PrintBits();
return 0;
}