aspose file tools*
The moose likes Beginning Java and the fly likes convert BigInteger to integer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "convert BigInteger to integer" Watch "convert BigInteger to integer" New topic
Author

convert BigInteger to integer

Valerie H.
Greenhorn

Joined: Dec 11, 2004
Posts: 6
Hello. I'm new to Java and I keep having problems doing conversions.

I am trying to convert a BigInteger to an integer in order to use
modPow(BigInteger exponent, BigInteger). I have enclosed my code below- any help or a recommended place to go would be appreciated.

BigInteger p;
BigInteger g;
BigInteger d;

int l = BigInteger.intValue(d);
BigInteger y = BigInteger.modPow(g l,p);

Thanks in advance.

Valerie
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30537
    
150

Valerie,
Starting from the API:
public BigInteger modPow(BigInteger exponent, BigInteger m)

First thing to note is that modPow is not a static method. This means that you call it on a specific BigInteger (in this case g.) It takes two BigIntegers (in this case d and p.) You don't need to convert to an int. This is good as you raise to exponents that are larger than can fit in an int. Finally, it returns a BigInteger (which you are storing in y.)

So now you have:


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Valerie H.
Greenhorn

Joined: Dec 11, 2004
Posts: 6
Jeanne-

I tried what you suggested and it worked great. Thanks for your help on this- I really appreciate it.

Valerie
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: convert BigInteger to integer