Large numbers calculation

373 Views Asked by At

I think this question has more mathematical background than computional, then I'm gonna ask it here.

I was thinking about large numbers calculation. Let's say I have the number $16777735$ stored in memory like this:

$256^0$ $256^1$ $256^2$ $256^3$ $256^4$ $256^5$
--$7$----$2$------$0$----$1$-----$0$-----$0$--

How can I write this number to screen, let's say, in base $10$? Imagine that I CANNOT sum all the parts like $7 + 256\cdot2 + 256^3$, like I couldn't deal with a byte of this size. (I'm only interested in the algorithm, so imagine I have a really large number that can't fit in to a byte, this is just an example)

And also, how to calculate, like, lots of digits of $\pi$, with this same method? I need a way to do these calculations. I'm interested in learning, so I'm asking about the mathematical process of this.

Thank you :)

1

There are 1 best solutions below

0
On

One method is to use the fairly standard method of converting to decimal, such as repeated remainders, eg you make up an array, and repeatedly divide the number by 10 (with carries), and carry the last digit over to the array.

For example, you divide 7.2.0.1 by 10, to get 205.153.25 r 5. You put 5 into a(0), and then go back for another digit, getting 97.142.2 remainder 3, the 3 is parked into a(1).

Another method that one could do, is to actually get your computer to work in decimal, like REXX does. There are papers by Mike Colishaw (who wrote REXX), about implementing decimal calculations in computer-arithmetic.