Computing.Net > Forums > Programming > Multiplication in VB

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Multiplication in VB

Reply to Message Icon

Name: BelAnWel
Date: February 17, 2003 at 18:47:19 Pacific
OS: 98
CPU/Ram: 256
Comment:

is it possible to add 2 numbers that are 200 digits long each in vb?



Sponsored Link
Ads by Google

Response Number 1
Name: borelli34
Date: February 17, 2003 at 21:53:24 Pacific
Reply:

It is not supported in any data types that are predefined in VB. The only way you could really do this is to store the numbers in string variables (variants may make it a bit easier) and write the math functions to preform the desired tasks on your strings. This can be tricky depending upon your application.

borelli34


0

Response Number 2
Name: tech-fred
Date: February 18, 2003 at 22:51:24 Pacific
Reply:

Using string functions addition is
relatively easy. When I first read the
posting I thought of multiplication. Since
the subject is multiplication.
There is(was) a BASIC program that does
arbitrary precision multiplication of
large multidigit numbers.

An extension of the method would use
arrays to store the partial products of
the multiplication. Then sum them.


0

Response Number 3
Name: tech-fred
Date: February 18, 2003 at 23:45:39 Pacific
Reply:

Here is a solution in BASIC.
tested to greater than 200 digits

rem long digit addition
rem PowerBasic 3.1 for DOS (should run in QBASIC)

x$ = "12345567778888444444444444444444444444"
y$ = "44444444444444444444444444999999004444"

rem find longer string and
rem pad shorter with leading "0"
a% = len(x$)
b% = len(y$)
c% = a%
if b% > a% then
c% = b%
x$ = repeat$((b%-a%), "0") + x$
else
y$ = repeat$((a%-b%), "0") + y$
end if

rem display inputs
print x$
print y$


rem work variables
z$ = ""
w% = 0
w$ = ""

rem working from end
for p% = c% to 1 step -1
x% = val(mid$(x$,p%,1))
y% = val(mid$(y$,p%,1))
s% = x% + y% + w%
s$ = str$(s%)
z$ = right$(s$,1) + z$

rem carry
if (len(s$) > 2) then
w$ = mid$(s$,2,1)
w% = val(w$)
else
w% = 0
end if
next p%

rem last carry
if (w% > 0) then
z$ = w$ + z$
end if

print z$

rem variables
rem x$ = first number string
rem y$ = second number string
rem z$ = output number string
rem a% = length of first number string
rem b% = length of second number string
rem c% = length of longest number string
rem w% = carry digit number
rem w$ = carry digit string
rem p% = position in number string


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Multiplication in VB

Print multipl lines in a cell in VB www.computing.net/answers/programming/print-multipl-lines-in-a-cell-in-vb/4945.html

Master-Detail Form in VB - How? www.computing.net/answers/programming/masterdetail-form-in-vb-how/2506.html

How to use Switch statement in vb www.computing.net/answers/programming/how-to-use-switch-statement-in-vb/6687.html