flat assembler
Message board for the users of flat assembler.

 flat assembler > High Level Languages > Add Very Big Numbers Together in BASIC.
Author
mbr_tsr

Joined: 03 Apr 2011
Posts: 4863
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"
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

```
04 Jul 2014, 20:25
mbr_tsr

Joined: 03 Apr 2011
Posts: 4863
the reason i made it was someday i am going to have it convert binary into decimals for 128 bit math.
04 Jul 2014, 20:35
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

 Jump to: Select a forum Official----------------Blog General----------------MainDOSWindowsLinuxUnixMenuetOS Specific----------------MacroinstructionsCompiler InternalsIDE DevelopmentOS ConstructionNon-x86 architecturesHigh Level LanguagesProgramming Language DesignProjects and IdeasExamples and Tutorials Other----------------FeedbackHeapTest Area

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