7 throw "BigUnsignedInABase::BigUnsignedInABase(const Digit *, Index, Base): The base must be at least 2";
10 for (
Index i = 0; i < l; i++)
12 throw "BigUnsignedInABase::BigUnsignedInABase(const Digit *, Index, Base): A digit is too large for the specified base";
19 unsigned int bitLen(
unsigned int x) {
27 unsigned int ceilingDiv(
unsigned int a,
unsigned int b) {
28 return (a + b - 1) / b;
35 throw "BigUnsignedInABase(BigUnsigned, Base): The base must be at least 2";
40 int minBitsPerDigit = bitLen(base) - 1;
41 int maxDigitLenOfX = ceilingDiv(maxBitLenOfX, minBitsPerDigit);
48 while (!x2.isZero()) {
65 while (digitNum > 0) {
76 throw "BigUnsignedInABase(std::string, Base): The default string conversion routines use the symbol set 0-9, A-Z and therefore support only up to base 36. You tried a conversion with a base over 36; write your own string conversion routine.";
83 len =
Index(s.length());
86 Index digitNum, symbolNumInString;
87 for (digitNum = 0; digitNum <
len; digitNum++) {
88 symbolNumInString = len - 1 - digitNum;
89 char theSymbol = s[symbolNumInString];
90 if (theSymbol >=
'0' && theSymbol <=
'9')
91 blk[digitNum] = theSymbol -
'0';
92 else if (theSymbol >=
'A' && theSymbol <=
'Z')
93 blk[digitNum] = theSymbol -
'A' + 10;
94 else if (theSymbol >=
'a' && theSymbol <=
'z')
95 blk[digitNum] = theSymbol -
'a' + 10;
97 throw "BigUnsignedInABase(std::string, Base): Bad symbol in input. Only 0-9, A-Z, a-z are accepted.";
99 if (
blk[digitNum] >= base)
100 throw "BigUnsignedInABase::BigUnsignedInABase(const Digit *, Index, Base): A digit is too large for the specified base";
105 BigUnsignedInABase::operator std::string()
const {
107 throw "BigUnsignedInABase ==> std::string: The default string conversion routines use the symbol set 0-9, A-Z and therefore support only up to base 36. You tried a conversion with a base over 36; write your own string conversion routine.";
109 return std::string(
"0");
111 char *s =
new char[len + 1];
113 Index digitNum, symbolNumInString;
114 for (symbolNumInString = 0; symbolNumInString < len; symbolNumInString++) {
115 digitNum = len - 1 - symbolNumInString;
116 Digit theDigit = blk[digitNum];
118 s[symbolNumInString] = char(
'0' + theDigit);
120 s[symbolNumInString] = char(
'A' + theDigit - 10);
void divideWithRemainder(const BigUnsigned &b, BigUnsigned &q)
static const unsigned int N
void multiply(const BigUnsigned &a, const BigUnsigned &b)
unsigned short toUnsignedShort() const