-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathBigInt.cpp
More file actions
81 lines (71 loc) · 1.36 KB
/
BigInt.cpp
File metadata and controls
81 lines (71 loc) · 1.36 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
#include "BigInt.h"
#include <QDebug>
BigInt::BigInt(quint64 val)
:m_data()
{
m_data.clear();
m_data.push_back((char) 0);
operator =(val);
}
BigInt::BigInt(const BigInt &in)
:m_data(in.m_data)
{
}
void BigInt::operator=(const BigInt &in)
{
m_data = in.m_data;
}
void BigInt::operator =(quint64 val)
{
int index = 0;
while (val > 0)
{
char byte = val & 0xff;
if (index >= m_data.size())
{
m_data.push_back((char) 0);
}
m_data.data()[index++] = byte;
val >>= 8;
}
}
void BigInt::increase()
{
for(int i = 0; i < m_data.size(); ++i)
{
if (((unsigned char*) m_data.data())[i] < (unsigned char) 0xff)
{
((unsigned char*) m_data.data())[i]++;
return;
}
else
{
((unsigned char*) m_data.data())[i] = 0x0;
}
}
m_data.push_back((unsigned char) 0x1);
}
const QByteArray BigInt::getData() const
{
return m_data;
}
void BigInt::setData(const QByteArray &in)
{
m_data.clear();
m_data = in;
}
bool operator==(const BigInt &a, const BigInt &b)
{
if (a.m_data.size() != b.m_data.size())
{
return false;
}
for(int i = 0; i < a.m_data.size(); ++i)
{
if (a.m_data[i] != b.m_data[i])
{
return false;
}
}
return true;
}