blob: f4ea40798909048eed0e97be1ceb8015870991a5 (
plain)
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
|
#ifndef CBIGINT_H
#define CBIGINT_H
/**
* An integer number with unlimited number of digits. Low digit is at low address.
*
* @author Walter Roth
*/
//define the base type of the number here. Useable types are: char, short int
typedef char BaseType;
struct BaseStruct
{
BaseType low;
BaseType high;
};
union LongBaseType
{
short int allSegments;
BaseStruct Segment;
};
class CBigInt
{
public:
/**
* Default constructor. Creates a number with size zero digits.
* Converts value to it's CbigInt representation.
*/
CBigInt(int value = 0);
/**
* Copy constructor. Creates a deep copy.
*/
CBigInt(const CBigInt & toCopy);
/**
* Destructor frees memory.
*/
~CBigInt();
/**
* Sets the new size, allocates memory and initializes with 0.
* If newSize is smaller than old,* _Size is reduced as long as
* digits to delete are zero. Returns final size.
*/
int setSize(int newSize);
/**
* Returns the number of digits available (_Size)
*/
int size() const;
/**
* Sets digit at position to value
*/
void setDigit(int pos, BaseType value);
/**
* Operator +
*/
CBigInt operator +(const CBigInt & n2);
/**
* Returns the number as a hexadecimal string
*/
const char * toHexString()const;
/**
* Returns true, if LongBaseType is twice the size of BaseType
*/
static bool isLongOk();
private:
/**
* Make a deep copy
*/
void copy(const CBigInt & toCopy);
private:
/**
* The start of the digit-array. Points to LSB.
*/
BaseType * _Digits;
/**
* The number of Digits allocated.
*/
int _Size;
/**
* The string buffer for toXXString functions
*/
static char * _StringBuffer;
}
#endif // CBIGINT_H
|