Results 1 to 9 of 9
Thread: BigInteger
- 01-09-2009, 07:53 PM #1
Member
- Join Date
- Jan 2009
- Posts
- 1
- Rep Power
- 0
- 01-09-2009, 08:28 PM #2
Senior Member
- Join Date
- Nov 2008
- Posts
- 286
- Rep Power
- 5
What do you want to know that the javadoc doesn't tell you?
Neil Coffey
Javamex - Java tutorials and performance info
- 01-10-2009, 02:37 AM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Yes on what you are confused, can you more clear-up your question here?
- 01-10-2009, 01:18 PM #4
Member
- Join Date
- Sep 2008
- Posts
- 43
- Rep Power
- 0
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 01:20 PM.
- 01-10-2009, 02:21 PM #5
Senior Member
- Join Date
- Nov 2008
- Posts
- 286
- Rep Power
- 5
No limit to all intents and purposes
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).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 holdNeil Coffey
Javamex - Java tutorials and performance info
- 01-10-2009, 05:46 PM #6
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
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, 04:03 PM #7
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
- 01-11-2009, 04:39 PM #8
Member
- Join Date
- Sep 2008
- Posts
- 43
- Rep Power
- 0
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 #9
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Actually this is a very old thread, over an year ago posted.
Similar Threads
-
How to convert a string into a BigInteger
By valery in forum New To JavaReplies: 4Last Post: 09-13-2011, 01:32 PM -
how to convert from BigInteger to Hex
By nanaji in forum Advanced JavaReplies: 10Last Post: 05-22-2008, 12:44 PM -
BigInteger remainder results in zero
By perito in forum New To JavaReplies: 1Last Post: 03-21-2008, 04:07 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks