flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > High Level Languages > Add Very Big Numbers Together in BASIC.

Author
Thread Post new topic Reply to topic
mbr_tsr



Joined: 03 Apr 2011
Posts: 4573
Add Very Big Numbers Together in BASIC.

Code:

print "======================================"
print "Adder Version 1.0 by S.T.C."
print "Add 2 numbers Max is 1 with 79 zeros"
print "Handles Very Big Numbers!!!"
print "======================================"
print "Number1?";
input ns1$;
print ""
print "Number2?";
input ns2$;
print ""
L1 = len(ns1$)
L2 = len(ns2$)
if L1 = L2 then
L = L1
s1$ = ns1$
s2$ = ns2$
endif
if L1 > L2 then
L = L1
s1$ = ns1$
s2$ = ns2$
else
L = L2
s1$ = ns2$
s2$ = ns1$
endif

P1 = len(s1$)
P2 = len(s2$)
P3 = P1 - P2
P$ = ""
FOR Pad = 1 to P3
P$ = P$ + "0"
Next Pad
s2$ = P$ + s2$

X = L
carry1$ = ""
ans$ = ""
for J = 1 to 80
a1$ = mid$(s1$,X,1)
a2$ = mid$(s2$,X,1)
if X < 1 then
if carry1$ = "" then
goto Done:
endif
a1$ = "0"
a2$ = "0"
endif
if a2$ = "" then
a2$ = "0"
endif
m1 = val(a1$)
m2 = val(a2$)
m3 = m1 + m2
if carry1$ > "" then
carry1$ = ltrim$(carry1$)
v = val(carry1$)
m3 = m3 + v
carry1$ = ""
endif
tst$ = str$(m3)
tst$ = ltrim$(tst$)
tst1 = len(tst$)
use$ = tst$
if tst1 > 1 then
carry1$ = mid$(tst$,1,1)
use$ = mid$(tst$,2,1)
endif
ans$ = use$+ans$
X = X - 1
next J
Done:
print "======================================"
print "Sum    =";
print ans$
print "======================================"
k$ = ""
while k$ = ""
k$ = inkey$
wend
END




Post 04 Jul 2014, 20:25
View user's profile Send private message Reply with quote
mbr_tsr



Joined: 03 Apr 2011
Posts: 4573
the reason i made it was someday i am going to have it convert binary into decimals for 128 bit math.
Post 04 Jul 2014, 20:35
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >

Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2005 phpBB Group.

Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2016, Tomasz Grysztar.