?
Solved

How to do very long division and mod operations

Posted on 2000-03-31
7
Medium Priority
?
206 Views
Last Modified: 2010-05-18
Does anyone have any ideas on how to implement in C, (or any other modern language) algorithms that will do long division and compute modulo values for very long numbers, on the order of 512 bits?  Most integers are 16, 32, or at most 64 bits.  Any known URLs about this subject would be helpful.  I would also be interested in any books that address the subject with good examples.
0
Comment
Question by:mzehner
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 8

Accepted Solution

by:
stochastic earned 300 total points
ID: 2675430
a. http://www.bearcave.com/software/divide.htm

b. http://barnyard.syr.edu/longdiv.html

Strangely, I am not finding many good URLs with ready downloadable code. Am tempted to write it myself :-)

- stochastic
0
 
LVL 22

Expert Comment

by:cookre
ID: 2675500
Donald E. Knuth
The Art of Computer Programming
Vol. 2
0
 
LVL 1

Expert Comment

by:ntdragon
ID: 2675914
i got idea for you
use strings instead of int or anyother

write your numbers in string's and make
the operations on it
like

operation +
first num 894
second num 327

 894
+
 327
-----
1221
the same with the other operations
what i mean is that you will have to do the operation by yourself for each place in the string

first the last place 4+7=11 so in the answer string you put 1 and move 1 forward
then 9+2+1<this 1 moved from the last>
=12 then you put 2 and move 1 to the next level
then 8+3+1<the 1 from the last level>=12
you put 2 in the answer string and
you put 1 in the next level of the answer string
 
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:ntdragon
ID: 2675915
i made it with operation +
you can do that with all the other operations like /,%,*,-
0
 
LVL 10

Expert Comment

by:rbr
ID: 2679284
I can send you a code which will do all basic operations /, *, +, -, %, for integers any length and base. The functions are not very fast but well tested and gives you a first impress who to do so. Writen an email to

rbr@tip-informatik.at because the code is to long to be pasted here.
0
 
LVL 2

Author Comment

by:mzehner
ID: 2736802
Thanks for taking the time to answer.  Although this code should work, it performs division on long ASCII strings and I do not believe it will be fast enough for my application.
0
 
LVL 2

Author Comment

by:mzehner
ID: 2736809
The "barnyard" web site was not helpful since it did long division over the web and the code seemed to be on the server side.  However the "bearcave" web site was helpful since it had several references to other documents which described long division algorithms.  The comment by cookre was also very good and I would have split the points between the two of you if I could.  I accepted this answer since some of the documents brought the theoretical algorithms closer to the practical.  It also referenced Knuth.  Thanks for posting your comments.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question