431,650 Members | 812 Online
Need help? Post your question and get tips & solutions from a community of 431,650 IT Pros & Developers. It's quick & easy.

# to add 2 very long integers

 P: n/a hi is anyone tell me any idea about to add 2 integers having more than 20 digits. e.g. 125865235989523352897956+565896589795623968955632. Apr 19 '06 #1
6 Replies

 P: n/a vicky_in wrote: hi is anyone tell me any idea about to add 2 integers having more than 20 digits. e.g. 125865235989523352897956+565896589795623968955632. Your platform might support built-in or extenstions for integers of sufficicent size (e.g., long, long long, __int64, __int128, etc.) for your needs, you could use a floating point representation if the least significant digits aren't important, or you could use a third-party big int library that allows for integers of arbitrary length (cf. http://www.parashift.com/c++-faq-lit...html#faq-37.9). Cheers! --M Apr 19 '06 #2

 P: n/a vicky_in wrote: is anyone tell me any idea about to add 2 integers having more than 20 digits. e.g. 125865235989523352897956+565896589795623968955632. Google "bigint". That's the common name for a class library that manages arbitrary-size integers. The answer to the actual question is to express the integer as an array of ints, where each element is a "place" in counting theory, just like elementary school arithmetic. Except instead of a 10s place, you have a ~2 billions place. Then to add you detect overflows, and carry to the next place. -- Phlip http://www.greencheese.org/ZeekLand <-- NOT a blog!!! Apr 19 '06 #3

 P: n/a "vicky_in" writes: is anyone tell me any idea about to add 2 integers having more than 20 digits. e.g. 125865235989523352897956+565896589795623968955632. If it is a practical problem, there are several libraries that handle big integers. Lists of libraries are posted occasionally to this group and/or comp.language.c. You could find a recent list using Google groups. If it is learning thing, the easiest way is probably to write a BCD adder, since it minimizes the conversion to/from binary problems. Apr 19 '06 #4

 P: n/a "vicky_in" skrev i meddelandet news:11**********************@i39g2000cwa.googlegr oups.com... hi is anyone tell me any idea about to add 2 integers having more than 20 digits. e.g. 125865235989523352897956+565896589795623968955632. Hi, You have two options; 1) Program basic addition between two natural numbers (of arbitrary size). I guess you know how. 2) Use a third party library that performs the above mentioned addition. Regards, Peter Jansson Apr 19 '06 #5

 P: n/a vicky_in wrote: hi is anyone tell me any idea about to add 2 integers having more than 20 digits. e.g. 125865235989523352897956+565896589795623968955632. http://www.swox.com/gmp/ -- Paul M. Dubuc Apr 19 '06 #6

 P: n/a In message <11**********************@i39g2000cwa.googlegroups .com>, vicky_in writeshi is anyone tell me any idea about to add 2 integers having more than20 digits.e.g. 125865235989523352897956+565896589795623968955632. How would you do it with paper and pencil? If you write down the rules for that, you are half way to designing a program that will do it for you. -- Richard Herring Apr 19 '06 #7

### This discussion thread is closed

Replies have been disabled for this discussion.