Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

100 Digit Numbers

3 views
Skip to first unread message

Simon Bale

unread,
Apr 2, 1997, 3:00:00 AM4/2/97
to

Can any one suggest a method of working with 100 digit numbers. Basically I
need to perform various mathematical calculations on them.

Thanks
___________________________________________

Simon Bale

Simon...@btinternet.com
___________________________________________

Jonathan Kirwan

unread,
Apr 2, 1997, 3:00:00 AM4/2/97
to

On Wed, 02 Apr 1997 17:15:56 -0500, Kodi <ko...@ix.netcom.com>
wrote:

>Simon Bale wrote:
>>
>> Can any one suggest a method of working with 100 digit numbers. Basically I
>> need to perform various mathematical calculations on them.
>>
>

>You would need at least 37 bits in an integer to represent 100 decimal
>digits, 38 if you want it to be signed. I would suggest using a six or
>eight byte integer (FWORD or QWORD) to get this. If you don't know how
>to do math on large integers, you should look at these three pages from
>Randall Hyde's "The Art of Assembly Language Programming."

37 or 38 bits? Try 333 bits, not counting the sign.

Of course, I'm wondering if the questioner just wanted to work
with numbers having big exponents, rather than 100 digits of
precision.

Jon

Kodi

unread,
Apr 2, 1997, 3:00:00 AM4/2/97
to

Simon Bale wrote:
>
> Can any one suggest a method of working with 100 digit numbers. Basically I
> need to perform various mathematical calculations on them.
>

You would need at least 37 bits in an integer to represent 100 decimal
digits, 38 if you want it to be signed. I would suggest using a six or
eight byte integer (FWORD or QWORD) to get this. If you don't know how
to do math on large integers, you should look at these three pages from
Randall Hyde's "The Art of Assembly Language Programming."

http://webster.ucr.edu/Page_asm/ArtofAssembly/CH09/CH09-3.html
http://webster.ucr.edu/Page_asm/ArtofAssembly/CH09/CH09-4.html
http://webster.ucr.edu/Page_asm/ArtofAssembly/CH09/CH09-5.html

They explain how to add, subtract, multiply, divide, and, or, xor,
negate, shift, rotate, and compare integers of any size.

Roland Persson

unread,
Apr 3, 1997, 3:00:00 AM4/3/97
to

Kodi wrote:

Simon Bale wrote:
>
> Can any one suggest a method of working with 100 digit numbers.
Basically I
> need to perform various mathematical calculations on them.
>

You would need at least 37 bits in an integer to represent 100
decimal
digits, 38 if you want it to be signed. I would suggest using a six
or
eight byte integer (FWORD or QWORD) to get this. If you don't know
how
to do math on large integers, you should look at these three pages
from
Randall Hyde's "The Art of Assembly Language Programming."

Hmm... Actually about 320+ bits would be needed.
In the GNU C++ library there is a class called Integer that you could
look at for ideas.

Roland


Binyamin Dissen

unread,
Apr 3, 1997, 3:00:00 AM4/3/97
to

On Wed, 02 Apr 1997 17:15:56 -0500 Kodi <ko...@ix.netcom.com> wrote:

[Posted and mailed]

:>Simon Bale wrote:

:>> Can any one suggest a method of working with 100 digit numbers. Basically I
:>> need to perform various mathematical calculations on them.

:>You would need at least 37 bits in an integer to represent 100 decimal
:>digits, 38 if you want it to be signed.

2**37 = 137438953472 =~ 10**11 = 12 digits or so.

Log2(10**100) =~ 332 which means you need 333 bits.

[ snipped ]

--
Binyami...@theoffice.net
Binyamin Dissen <bdi...@netvision.net.il>

Binyamin Dissen

unread,
Apr 3, 1997, 3:00:00 AM4/3/97
to

On 2 Apr 1997 13:48:11 GMT "Simon Bale" <Simon...@btinternet.com> wrote:

[Posted and mailed]

:>Can any one suggest a method of working with 100 digit numbers. Basically I
:>need to perform various mathematical calculations on them.

Break the number into sections.

Addition and subtraction do like you did 32 bit numbers in 8 bit registers.

Multiplication can be done on segments and then summed as below.
(a+b+c+d) * (w+x+y+z) = aw+ax+ay+az+bw+bx+by+bz+cw+cx+cy+cz+dw+dx+dy+dz

I have done divisions by shifting and comparing/subtracting. There probably
are better ways.

:>Thanks

Director, Dissen Software, Bar & Grill - Israel


Jerzy Tarasiuk

unread,
Apr 4, 1997, 3:00:00 AM4/4/97
to

>>>>> Binyamin Dissen <Binyami...@theoffice.net> writes:
> Multiplication can be done on segments and then summed as below.
> (a+b+c+d) * (w+x+y+z) = aw+ax+ay+az+bw+bx+by+bz+cw+cx+cy+cz+dw+dx+dy+dz

Need just multiply "each times each" and sum to proper places.
Take care about carry generated by every addition... maybe some
medieval method can be useful: every time you multiply two words
you get two words (high and low) of result, these high must go
to sums one position above the low; also whenever carry out is
generated sum it to extra array and later add the array to sum.
Example - multiply 34*56
5 6
4 * 0 * 4
2 2 \
3 * 5 * 8 \
1 1 \ \
\ \ \ \
sum: 1 8 0 4
carry: 0 1 0
result: 1 9 0 4

> I have done divisions by shifting and comparing/subtracting. There probably
> are better ways.

Need first normalize divisor (i.e. shift it left until highest bit
of most meaningful word becomes one), then divide by the value of
word plus one (no divide at all if got ffff after normalizing).
First non-zero word of result (no need to compute more on this
step) can be first word of correct result, or be less by one -
need multiplication of entire divisor by the "result" then few
compares/subtracts to fix this result. And then next words...

Kjetil E. Furnes

unread,
Apr 5, 1997, 3:00:00 AM4/5/97
to

Simon Bale wrote:
>
> Can any one suggest a method of working with 100 digit numbers. Basically I
> need to perform various mathematical calculations on them.
>

Lets say you got number the numbers 1 and 2.
first you break it into bytes/words/doublewords.

lets use words.
a has the least significant bit.
1 = 1a 1b 1c 1d
2 = 2a 2b 2c 2d
SUM = Sa Sb Sc Sd

mov AX, 1a
add AX, 2a ; if there's an overflow, the carry flag will be set.
mov Sa, AX
Loop:
mov AX, 1b
adc AX, 2b ; if carry is set it will increase the sum by one.
mov Sa, AX

here's the problem, either you must push the flags so that in a way
they're pop'ed
when you jump to Loop (we need to know wether carry is set.) or you can
repeat the adc's.
mov AX, 1c
adc AX, 2c ; if carry is set it will increase the sum by one.
mov Sa, AX
mov AX, 1d
adc AX, 2d ; if carry is set it will increase the sum by one.
mov Sa, AX

To subtract, you do the same, but you use sub and sbb.

The multiplication is easy to. As many of you know, you can use shl for
fast
multiply. Many also know that you can combine different shl to get
exactly the value
you want, but I've discovered something about it. if you start at the
least significant
byte, and test if it's set, if it is, the you add the value you are
mulipicating to the
product, then shl the value and test the next bit.

I can't help you on the division yet, I haven't figured any workable way
to do this.


> Thanks

Any time.


P.S. Sorry if this is messy, mail me if there's something you don't
understand.


- Kjetil Furnes


I've got a...uh...uh...Oh yeah- a photographic memory!

0 new messages