Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

BigIntegers...

 
Marcus Laubli
Ranch Hand
Posts: 116
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've spent over an hour on this.

I'm trying to add two BigIntegers and have some kind of knot somewhere. Can someone please help me add 1 + 1 using the BitInteger Object, then add A third one to the result of 1 + 1?

I feel so dumb.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Instances of BigInteger are objects, so regular numeric operators won't work. Instead, you call methods, defined in the API...

http://java.sun.com/j2se/1.5.0/docs/api/java/math/BigInteger.html

For example, to add existing BigInteger instances b1 and b2, then assign the result to b3, you could do the following...

BigInteger b3 = b1.add(b2);

Note that the sum is returned by the method, which does not change the values of b1 or b2.

Also note that "1" is a special constant, so you don't need to create your own instance. You can simply use BigInteger.ONE.
[ February 18, 2005: Message edited by: marc weber ]
 
Igor Stojanovic
Ranch Hand
Posts: 58
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here you can find "short code samples" for operations whic involve BigIntegers :

Java Almanac

Also try to search for other "code samples" before posting your question here, I found many answers there. I hope it will help you

kind regards
Igor
 
Marcus Laubli
Ranch Hand
Posts: 116
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.

If I hadn't spent the time on it, I wouldn't have asked. I usually search here and Google befor I come for assistance.
 
Igor Stojanovic
Ranch Hand
Posts: 58
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not sure if You did actually read information provided by that link since its very straightforward and as i can see you have sun certificate so I asume you should be able to get your code working from this example which is provided by above link




kind regards
Igor
 
Layne Lund
Ranch Hand
Posts: 3061
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are a certified SCJP and you don't know how to look up this information in the Java API documentation? That just scares me...

Layne
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic