• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

BigIntegers...

 
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic