Meaningless Drivel is fun!
The moose likes Java in General and the fly likes BigInteger Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "BigInteger" Watch "BigInteger" New topic


Robbie Harjes

Joined: Nov 09, 2003
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:

Joe Pluta
Ranch Hand

Joined: Jun 23, 2003
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);
Marilyn de Queiroz

Joined: Jul 22, 2000
Posts: 9055
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 ]

"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Robbie Harjes

Joined: Nov 09, 2003
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

Joined: Oct 02, 2003
Posts: 11575

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();

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
I agree. Here's the link:
subject: BigInteger