s = s + h;
}
}
else {
// This is algorithm 1a from chapter 4.4 in Seminumerical Algorithms, slow but it works
Stack S = new Stack();
BigInteger base = new BigInteger(Integer.toString(rdx, rdx), rdx);
// The sign is handled separatly.
// Notice however that for this to work, radix 16 _MUST_ be a special case,
// unless we want to enter a recursion well. In their infinite wisdom, why did not
// the Sun engineers made a c'tor for BigIntegers taking a BigInteger as parameter?
// (Answer: Becuase Sun's BigIntger is clonable, something bouncycastle's isn't.)
BigInteger u = new BigInteger(this.abs().toString(16), 16);
BigInteger b;
// For speed, maye these test should look directly a u.magnitude.length?
while (!u.equals(BigInteger.ZERO)) {
b = u.mod(base);
if (b.equals(BigInteger.ZERO)) {
S.push("0");
}
else {
S.push(Integer.toString(b.mag[0], rdx));
}
u = u.divide(base);
}
// Then pop the stack
while (!S.empty()) {
s = s + S.pop();
}
}
// Strip leading zeros.
while (s.length() > 1 && s.charAt(0) == '0') {
s = s.substring(1);