Win a copy of Design for the Mind this week in the Design forum!

BigInteger

Robbie Harjes
Greenhorn
Posts: 22
BigInteger's are fun!, not. To set up some initial values for some BigInteger testing...
doesn't work... So what is the "standard" format? (The best conclusion I've come to is that there not exactly standardized, seeing how the length can change..? i don't know) And how do I convert/cast/whatever method I need for this to work:

Thanks.

Joe Pluta
Ranch Hand
Posts: 1376
BigInteger and its sibling BigDecimal are objects, and so you create them using the "new" keyword:
BigInteger myBI = new BigInteger(7);
BigDecimal myBD = new BigDecimal(1.23);
Joe

Marilyn de Queiroz
Sheriff
Posts: 9059
12
Check out the methods of the BigInteger class to find out how to convert from an int to a BigInteger and back again (although if the number will fit into an int, I wonder why you would want to use BigInteger).
[ December 01, 2003: Message edited by: Marilyn de Queiroz ]

Robbie Harjes
Greenhorn
Posts: 22
Well thanks for the help... But I've come down to just 2 compile time errors. Here's the source code for the program (It's only to find the mod function [remainder] of very large exponential monomials.)

I changed some of the code... realized that the values Y and A are going to be small, but it's only the result of Y^A that requires the BigInteger.
Finally, here are the compile-time errors:

[ December 01, 2003: Message edited by: Robbie Harjes ]

fred rosenberger
lowercase baba
Bartender
Posts: 12097
30
Forgive me, but what am i missing??? i don't see a constructor for BigInteger that accepts an int. i think that's what the compiler is complaining about.
you can pass it a string...
BigInteger big = new BigInteger("7");
that seems to fix one error...
the other is that BigInter.mod() takes a BigInteger, not a long...
and then...
intvalue doesn't take any parameter, you just call it on your BigInteger object you want the value of...
integer i = big.intvalue();