View Single Post
  #2   Report Post  
Myrna Larson
 
Posts: n/a
Default

Here's some VBA code. The input must be a decimal number. The new base must be
between 2 and 36.

Several routines have been posted in the past by Harlan Grove, Ron Rosenfeld,
and myself, perhaps others. You should find code that will convert a
non-decimal number to some other base, 10 or otherwise.

Google can find the code for you.

But 347472963 is 14B60443 in hex. Conversely, ABC123 is 11256099 in decimal.


Function ConvertBase(ByVal lValue As Variant, iBase As Integer) _
As String
'convert a base-10 number to a new base
'will handle an integer with 15 decimal sDigits, which is the
'limit of precision for a double
Const sDigits = "123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Const MaxLen = 56
Dim IsNeg As Boolean
Dim sNumber As String
Dim p As Integer
Dim iDigit As Integer
Dim PrevValue As Variant

'Trap base value errors
If (iBase 36) Or (iBase < 2) Then Exit Function

IsNeg = False
If lValue < 0 Then
IsNeg = True
lValue = -lValue
End If

sNumber = String$(MaxLen, "0")
p = MaxLen + 1

Do While lValue 0
PrevValue = lValue
lValue = Int(lValue / iBase)
iDigit = PrevValue - lValue * iBase
p = p - 1
If iDigit Then Mid$(sNumber, p, 1) = Mid$(sDigits, iDigit, 1)
Loop

If p MaxLen Then p = p - 1

If IsNeg Then
p = p - 1
Mid$(sNumber, p, 1) = "-"
End If

ConvertBase = Mid$(sNumber, p)
End Function 'ConvertBase


On Sat, 15 Jan 2005 01:51:35 GMT, Wildman wrote:

anyone know how to change a nine digit number into a base 32 number?

change "347472963" to "abc123"


I have found away to convert a 6 charactor base 32 string to decimal
using a VLOOkup to change the alpha charactor to decimal.
but Im stuck going to other way.

Thanks to any help in advance.

Wildman