# BigInteger

• 01-09-2009, 08:53 PM
BigInteger
Can anyone tell me more about BigInterger.
I read a lot but the concept is not usual plz help...

Thanks
• 01-09-2009, 09:28 PM
neilcoffey
What do you want to know that the javadoc doesn't tell you?
• 01-10-2009, 03:37 AM
Eranga
Yes on what you are confused, can you more clear-up your question here?
• 01-10-2009, 02:18 PM
2potatocakes
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);
}
}

:)
• 01-10-2009, 03:21 PM
neilcoffey
No limit to all intents and purposes
Quote:

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).
• 01-10-2009, 06:46 PM
Eranga
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.
• 01-11-2009, 05:03 PM
Nicholas Jordan
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.
• 01-11-2009, 05:39 PM
2potatocakes
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 ;)
• 07-13-2010, 01:10 PM
Eranga
Actually this is a very old thread, over an year ago posted.