Jump to content

Problem with base conversion algorithm


Drifter
 Share

Recommended Posts

This algorithm is supposed to convert base 10 to base 48.

Func convertNum($n)
    ;This function takes a base 10 number and converts it to base 48
    ;the values for each place are currently represented in decimal, but will soon be shown as a-z and A-V.

    ;Find the highest base 48 value that we will need.
    $j = 0

    While 1
        If (48^$j * 48) - 1 <= $n Then
            $j += 1
        Else
            ExitLoop(1)
        EndIf

    WEnd

    ;$j now contains the highest power of 48 needed.
    Local $outArray[$j + 1]
    $outStr = ""

    For $k = $j To 0 Step -1
        ;represent the value for this place
        $outArray[$k] = Int($n / (48 ^ $k))

        ;remove it from the original number
        $n -= ($outArray[$k] * (48 ^ $k))

    Next

    For $i = 0 To $j
        ;show the values for each place, seperated by a comma.
        $outStr &= $outArray[$i] & ","
    Next

    Return $outStr

EndFunc

What exactly is wrong?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...