-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
83 lines (59 loc) · 3.91 KB
/
main.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
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
#include <iostream>
#include "bright.h"
using namespace std;
int main()
{
// 输入
// 自动隐式类型转换
Bright a = 10;
// from a long long int
Bright b(123456);
// from a really long number
Bright c("262019165839795466636015683089358648091");
// from a really long hex (or oct) number
Bright d("C51F0E45981B5BACA24281DB78E3F31B", 16);
// from 4 * 2^30 bytes (2^120 bytes total)
Bright e;
e.unshift(Bright::mask); // mask is just 2^30-1, 111111111111111111111111111111
e.unshift(Bright::mask);
e.unshift(Bright::mask);
e.unshift(Bright::mask);
// from input stream
// Bright e;
// cin >> e;
// from hex input stream (or oct)
// Bright f;
// cin >> hex >> f;
// 输出
// output stream
cout << "a is: " << a << endl;
cout << "b(oct) is: " << oct << b << endl;
cout << "c(hex) is: " << hex << c << endl;
cout << "d(dec) is: " << dec << d << endl;
// get string (support base 2, 8, 10, 16)
cout << "e(bin) is: " << e.toStr(2) << endl;
cout << endl;
// 获得长度
cout << "bit length of e is: " << dec << e.size() << endl;
cout << endl;
// 大小比较
cout << "a > b?\t" << boolalpha << (a > b) << endl;
cout << "a <= b?\t" << boolalpha << (a <= b) << endl;
cout << "c == d?\t" << boolalpha << (c == d) << endl;
cout << "c != d?\t" << boolalpha << (c != d) << endl;
cout << endl;
// 运算
cout << "c + d = " << c + d << endl;
cout << "c * 2 = " << c * 2 << endl;
cout << "c % c = " << c % c << endl;
cout << "c * d = " << hex << c * d << endl;
cout << "c / (d / 2) = " << dec << c / (d / 2) << endl;
cout << "c % (d / 2) = " << dec << c % (d / 2) << endl;
cout << endl;
// 2^30 进制移位
cout << "e >> 3 = " << (e >> 3).toStr(2) << endl;
cout << "1 << 9 = " << hex << (Bright(1) << 9) << endl;
cout << endl;
return 0;
}