Results 1 to 9 of 9

Thread: BigInteger

  1. #1
    windows.login is offline Member
    Join Date
    Jan 2009
    Posts
    1
    Rep Power
    0

    Default BigInteger

    Can anyone tell me more about BigInterger.
    I read a lot but the concept is not usual plz help...

    Thanks
    Paddy
    pradyumna.wordpress.com

  2. #2
    neilcoffey is offline Senior Member
    Join Date
    Nov 2008
    Posts
    286
    Rep Power
    6

    Default

    What do you want to know that the javadoc doesn't tell you?

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  4. #4
    2potatocakes is offline Member
    Join Date
    Sep 2008
    Posts
    43
    Rep Power
    0

    Default

    Those javadocs can be difficult to understand sometimes though. Basically, the BigInteger class was created through java to help mathematicians or anybody really, wanting to make calculations with numbers that use large amounts of digits in those numbers.
    Because when you initialise a variable such as a normal int or a byte or a double or float or a long etc, a specific amount of memory is assigned to that variable.
    So far so good but because the variable is assigned an specific amount of memory it means that the variable can only contain a limited amount of data. Here's a couple of examples:

    a Byte of data being the smallest of the variables contains 8 bits. meaning that you can save any number between -128 and 127 as a Byte. It is small, meaning that the computer can read it very quickly but it cannot contain much data.
    int integers of data contain 32 bits of data and can hold values between -2,147,483,648 and 2,147,483,647
    long's of data contain 64 bits and can hold values between -9,223,372,036,854,775,808 and 9,223,372,036,854,775,807

    getting the drift...

    Problem is, you can't easily go higher than the value of the long using a primitive data type. To do that the the BigInteger class was created which, I'm am not 100% sure, but I'm pretty sure that it doesn't have an upper limit to the number of digits that it can hold. I'm assuming it holds the digits as either a String or Array of numbers or something. But that doesn't really matter unless you really wanna dive right into it.

    The basic idea is that you can do maths without having to worry about constraints to the size of the numbers that you can use. Here's basic example of it in use for you ;) All the best!

    import java.math.BigInteger;
    public class BigIntegerExample
    {
    public static void main(String[] args)
    {
    BigInteger bigInteger1 = new BigInteger ("12345674324324123434214343423434289");
    BigInteger bigInteger2 = new BigInteger ("11234334");
    BigInteger bigIntResult =
    bigInteger1.multiply(bigInteger2);
    System.out.println("Result is ==> " + bigIntResult);
    }
    }

    :)
    Last edited by 2potatocakes; 01-10-2009 at 02:20 PM.

  5. #5
    neilcoffey is offline Senior Member
    Join Date
    Nov 2008
    Posts
    286
    Rep Power
    6

    Default No limit to all intents and purposes

    I'm am not 100% sure, but I'm pretty sure that it doesn't have an upper limit to the number of digits that it can hold
    In theory, there's an upper limit of 2^32 ints' worth of magnitude (2^37 bits), but most people will run out of memory before they hit that limit (and on a 32-bit machine, the limit is actually impossible to reach).

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    I don't think that Java documents are difficult to understand. Actually there no explanation with examples. But in theory it explains well. Sometime you can find simple code segments.

  7. #7
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Default

    Yeah, actually there is a way to do BigInteger style mathematics using persistent register ( aka - hard disk ), also winnie will page out ram making virtual memory available ....

    the purpose of BigInteger involves operations that arise in the study of computer science - a good example, with commonly available beginner sample code is N! ( n- factorial )

    Neither a challenging concept nor hard to code, it is a mathematus that arrives soon in many science and math operations, I decided to put one in somewhere recently just for a cheap trick authentication routine ... I was really suprised how soon int ( primitive type ) would not hold the results of the iteration.

    BigInteger would go farther before not working correctly.

    There are many issues in authentication and verification that need the operations of Big Integer to be effective.
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

  8. #8
    2potatocakes is offline Member
    Join Date
    Sep 2008
    Posts
    43
    Rep Power
    0

    Default

    I never knew about that upper limit neilcoffey. Thanks! truth is, I don't have the patience to read the java docs properly. I'm only a beginner but I learn best from example... and also all you lovely people ;)

  9. #9
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. How to convert a string into a BigInteger
    By valery in forum New To Java
    Replies: 4
    Last Post: 09-13-2011, 02:32 PM
  2. how to convert from BigInteger to Hex
    By nanaji in forum Advanced Java
    Replies: 10
    Last Post: 05-22-2008, 01:44 PM
  3. BigInteger remainder results in zero
    By perito in forum New To Java
    Replies: 1
    Last Post: 03-21-2008, 05:07 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •