Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
universal base conversion program possibly for a base conversion library later on
#5
oh ok how do I do that???

Code: (Select All)
Dim dinpt, oput As String * 40
Dim dbase As String * 800
Dim dinput As String * 80
Dim dnum As String * 80
Dim whprt As String * 800
Dim fprt As String * 800
Dim gttl As String * 800
Dim qmlt As String * 80
Dim mlt As String * 80
Dim zee As String * 800
Dim sen As Long
Dim sign As Long
Dim ctr As Long
Dim flg As Long
Dim flg2 As Long
Dim lsplt As Long
Dim rsplt As Long
Dim pres As Long
Randomize Timer
Rem  $Dynamic
dinput = "000000000000"
Print "enter number to convert from incl.base use 4 digits for each digit include 0 in each of the 4 places thaat contains no value so 0 is 0000 and 1 is 0001 "
Print "first enter a base of at least 2 (0002) enter - for a negative number . for decimal point"
Input ": "; dinput
Print " in a similiar manner enter the base to convert too "
Input ": "; oput
sen = Len(dinput)
dbase = Left$(dinput, 4)
sen = sen - 4
dnum = Right$(dinput, sen)
sign = 1
sen = Len(dnum)
If Left$(dnum, 1) = "-" Then
    sign = -1
    sen = sen - 1
    dnum = Right$(dnum, sen)
End If
ctr = 1
flg = 0
flg2 = 0
While flg = 0 And ctr <= sen
    If Mid$(dnum, ctr, 1) = "." Then
        lsplt = ctr - 1
        rsplt = sen - ctr
        flg = 1
        If ctr = 1 Then flg2 = 1
    End If
    ctr = ctr + 1
Wend
If flg = 1 And flg2 = 0 Then
    whprt = Left$(dnum, lsplt)
    fprt = Right$(dnum, rsplt)
End If
If flg = 1 And flg2 = 1 Then
    whprt = "0000"
    fprt = Right$(dnum, rsplt)
    lsplt = 4
End If
gttl = "0"
qmlt = "1"
mlt = dbase
If flg = 0 Then whprt = dnum
While lsplt > 0
    zee = Right$(whprt, 4)
    gttl = mr(gttl, "+", mr(zee, "*", qmlt))
    qmlt = mr(qmlt, "*", mlt)
    lsplt = lsplt - 4
    whprt = Left$(whprt, lsplt)
Wend
pres = Int((Log(Val(dbase)) * Int(rsplt / 4)) / Log(Val(oput)))
qmlt = "1"
Rem  wqs&& = 1 to pres&&
qmlt = mr(qmlt, "/", dbase)
While rsplt >= 4
    zee = Left$(fprt, 4)
    gttl = mr(gttl, "+", mr(zee, "*", qmlt))
    qmlt = mr(qmlt, "/", dbase)
    rsplt = rsplt - 4
    fprt = Right$(fprt, rsplt)
Wend
Print "base ten value: "; gttl
like this?

that last post of mine is my latest it seems to be running some kind of error it prints out what looks like a fractional part but the whole number part is nowhere to be seen
Reply


Messages In This Thread
RE: universal base conversion program possibly for a base conversion library later on - by Dragoncat - 04-11-2025, 12:09 PM



Users browsing this thread: 1 Guest(s)