Next is how to write functions to transform decimal numbers to any radix (base) 2-62 and then back again.

It is now relatively easy to extend all of the previously explicated functions to allow transformation to and from any base 2-62 (where base 62 [0-9][A-Z][a-z]) which can also handle large numbers via the decimal datatype. The next function transforms a decimal number into any radix 2-62:
vb Code:
  1. Function DecTo(ByVal x, ByVal Radix&) As String
  2.  ' Witis transforms up to 27 digit positive integer from decimal to any base 2-62
  3.  If (Radix < 2) Or (Radix > 62) Then Exit Function
  4.  Dim y&: x = CDec(x)
  5.  Do
  6.     y = (x / Radix - Fix(x / Radix)) * Radix ' get dec value of the rightmost column given the radix
  7.     If y < 10 Then
  8.         DecTo = y & DecTo ' add a numerical digit
  9.     ElseIf y < 36 Then DecTo = Chr$(y + 55) & DecTo ' non num digit [A-Z]
  10.     ElseIf y < 62 Then DecTo = Chr$(y + 61) & DecTo ' non num digit [a-z]
  11.     End If
  12.     x = Fix(x / Radix) ' move the point to the left one place and discard the remainder
  13.  Loop While x
  14. End Function
This function determines the decimal value of the rightmost column given the radix and then converts it into the alpha numeric code [0-9][A-Z][a-z], then moves the point one place to the left until the entire number is transformed from decimal to the chosen radix.

For example 55 decimal to Hex which is (3A):
The first iteration works out that the rightmost column contains 0.625 of the radix or 10 which is represented by the letter A in hex.
The next iteration determines that the rightmost column contains 0.1875 of the radix or 3 which is also represented by 3 in hex.

The next function allows numbers from other radixes 2-62 to be transformed back into decimal:
Code:
Function ToDec(ByVal x, ByVal Radix&) As Variant
 ' Witis transforms any postive whole number from any base 2-62 to a decimal value
 If (Radix < 2) Or (Radix > 62) Then Exit Function
 Dim ba() As Byte, i&, bitval As Variant, b As Byte
 bitval = 1
 ba = StrConv(x, vbFromUnicode)
 For i = UBound(ba) To 0 Step -1
    b = ba(i)
    If b < 58 Then
        ToDec = CDec(ToDec + (b - 48) * bitval)
    ElseIf b < 91 Then ToDec = CDec(ToDec + (b - 55) * bitval)
    ElseIf b < 123 Then ToDec = CDec(ToDec + (b - 61) * bitval)
    End If
    bitval = CDec(bitval * Radix)
 Next i
End Function
This function checks each bit from right to left and works out it's numerical value in decimal, for example A in hex is 10 decimal. Then it simply multiplies this number by the bit value.

For example:
2A in hex
A = 10 decimal * bitvalue = 10 * 16^0 = 10
2 = 2 decimal * bitvalue = 2 * 16^1 = 32
so the answer 2A hex = 42 decimal

What about Octet?
67 Octet
7 = 7 * 8^0 = 7
6 = 6 * 8^1 = 48
so the answer is 55 decimal

Example usage to convert a 27 digit integer to every base 2-62 and back again; output is to the debug window (ctrl+g):
Code:
Private Sub Command1_Click()
Dim res, lbase&, i&
For i = 2 To 62 Step 1
    lbase = i
    res = DecTo("888888888888888888888888888", lbase)
    Debug.Print res
    res = ToDec(res, lbase)
    Debug.Print res
Next i
End Sub
If you can understand these functions, good job, you can now transform positive integers from decimal to any radix and back again including binary, hex and octal.