Misunderstanding with BigIntegers - no suprises there then...

Hi

I have a function for breaking down (supposedly) a BigInteger into a list, depending on the base! It works when I send it all my small test cases, however, when I do actually try and send it a 'big integer' it falls over, what am I doing wrong? Typical call line:

cc.split(234752138651249763254, BigInteger.valueOf(23472))

I keep getting an error stating that it is out of bounds!

Many thanks, Ron

public List split(BigInteger x, BigInteger b)

{

BigInteger t;

List<BigInteger> lst =new ArrayList<BigInteger>();

while (x.compareTo(BigInteger.ZERO) > 0)

{

BigInteger[] qr = x.divideAndRemainder(b);

x = qr[0];

t = qr[1];

lst.add(t);

}

//System.out.println(l.toString());

return lst;

}

[1085 byte] By [cakea] at [2007-10-2 11:59:42]
# 1
234752138651249763254sure looks out of bounds to me.Perhaps you wanted to make that a big integer as required by the parameters to the split function.
marlin314a at 2007-7-13 8:14:47 > top of Java-index,Other Topics,Algorithms...
# 2

Hi

How could i change the function so that I could feed it a pair of values of any length? Would I be better off feeding it in as a string and then coverting it, would that help me any? I have just started a course on cryptography and this is the first time I have ever come across the BigInteger class, and I am sorry if I come across as a bit thick when trying to use it!

Many thanks, Ron

cakea at 2007-7-13 8:14:47 > top of Java-index,Other Topics,Algorithms...
# 3

> Would I be better

> off feeding it in as a string and then coverting it,

> would that help me any?

You mean by using the BigDecimal(String) constructor? Of course you would. And what about the constructor that comes right after that in the documentation? Sounds like you might be able to make use of that one too, although it's hard to tell from your background information.

DrClapa at 2007-7-13 8:14:47 > top of Java-index,Other Topics,Algorithms...