4
* 2002-May-25 Jason Rohrer
11
#ifndef BIG_INT_INCLUDED
12
#define BIG_INT_INCLUDED
17
* A multi-byte integer representation.
19
* Some of the ideas used in this class were gleaned
20
* from studying Sun's Java 1.3 BigInteger implementation.
22
* @author Jason Rohrer.
33
* Constructs an integer.
35
* @param inSign the sign of this integer:
36
* -1 if negative, +1 if positive, and 0 if zero.
37
* @param inNumBytes the number of bytes in this integer.
38
* @param inBytes the bytes for this integer.
39
* Copied internally, so must be destroyed by caller.
41
BigInt( int inSign, int inNumBytes, unsigned char *inBytes );
46
* Constructs an integer from a 32-bit int.
48
* @param inInt the int to use.
59
* Adds an integer to this integer.
61
* @praram inOtherInt the int to add.
62
* Must be destroyed by caller.
64
* @return a newly allocated integer containing the sum.
65
* Must be destroyed by caller.
67
BigInt *add( BigInt *inOtherInt );
72
* Subtracts an integer from this integer.
74
* @praram inOtherInt the int to subtract.
75
* Must be destroyed by caller.
77
* @return a newly allocated integer containing the difference.
78
* Must be destroyed by caller.
80
BigInt *subtract( BigInt *inOtherInt );
85
* Gets whether this integer is less than another integer.
87
* @praram inOtherInt the integer test.
88
* Must be destroyed by caller.
90
* @return true if this integer is less than the other.
92
char isLessThan( BigInt *inOtherInt );
97
* Gets whether this integer is equal to another integer.
99
* @praram inOtherInt the integer test.
100
* Must be destroyed by caller.
102
* @return true if this integer is equal to the other.
104
char isEqualTo( BigInt *inOtherInt );
109
* Gets a copy of this integer.
111
* @return a newly allocated integer containing the copy.
112
* Must be destroyed by caller.
119
* Gets an integer equal to zero.
121
* @return a newly allocated integer containing zero.
122
* Must be destroyed by caller.
124
static BigInt *getZero();
129
* Converts this integer to a decimal string.
131
* @return a \0-terminated ascii decimal string.
132
* Must be destroyed by caller.
134
//char *convertToDecimalString();
139
* Converts this integer to a hex string.
141
* @return a \0-terminated ascii hexx string.
142
* Must be destroyed by caller.
144
char *convertToHexString();
149
* Converts this integer to a 32-bit int.
151
* If this integer contains more than 32-bits, the high-order
152
* bits will be discarded, though the sign will be preserved.
159
* -1 if negative, +1 if positive, and 0 if zero.
166
* Integer is stored in big endian byte order.
168
unsigned char *mBytes;
177
* Flips the byte order of this integer.
179
* @return a newly allocated integer containing the flipped version.
180
* Must be destroyed by caller.
182
BigInt *flipByteOrder();
187
* Computes the hex representation of a four-bit int.
189
* @param inInt the four-bit int to convert.
191
* @return the int as a hex ascii character,
192
* in {0, 1, ..., A, B, ..., F}.
194
char fourBitIntToHex( int inInt );