Click here to Skip to main content
15,885,767 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My question is, if I have a very large number how can I add and multiply these two numbers without using Big integer in Java??


EX :

23478653794837 * 834723742395729

or
23478653794837 + 834723742395729
Posted
Updated 5-Oct-15 18:49pm
v3

Quote:
if I have a very large number how can I add and multiply these two numbers without using Big integer in Java??
Big integers are done especially for this purpose.
If you don't want to use big integers, you will have to build yourself a set of functions that will mimic big integers.
The main difference is that you are unlikely to be as efficient as big integers.
Calculate the Factorial of an Integer in C#[^]

Search for big intergers to informations about it works. But since about every language have now a big integer library, you will be flooded with such answers. You will have to refine the query to find what you want.
 
Share this answer
 
v3
Comments
Matthew Dennis 5-Oct-15 23:12pm    
for an example of using BigInteger see my tip http://www.codeproject.com/Tips/270413/Calculate-the-Factorial-of-an-Integer-in-Csharp
Patrice T 6-Oct-15 3:28am    
Thank you.
incorporated in solution
[no name] 6-Oct-15 17:18pm    
thank you but I'm trying to do so without using BigInteger
[no name] 6-Oct-15 17:18pm    
thank you but I'm trying to do so without using BigInteger
Matthew Dennis 6-Oct-15 17:26pm    
Then you are probably trying to implement and divide-and-conquer algorithm for your Algorithms and Data Structures course.
When I took it, we had to calculate 72!, which has 100 digits. I had to do it in Pascal.
The trick is to break it into chunks that you can add or multiply, do the operation on the chucks, and then recombine them into a structure that can hold the result, possibly an array.
one classical way:
- treat your number like string.
- multiply & add like the way you did when you was a child.
sample:
23*45 = (5*3+ 5*10*2) + (4*3+4*10*2)*10

by this way, you can multiply & add all Big integers (like 1123222434324323233535345345345345435345454334543 343294324324302432
*23429492349329433289393895348958934540940958068594695486954864846805486
....
)
 
Share this answer
 
v2
Comments
CPallini 7-Oct-15 5:05am    
5.This is an option.
Member 12039237 7-Oct-15 5:13am    
In the past (before y2k), I have to add two numbers (one hundred digit numbers).
and I did it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900