PC Review


Reply
Thread Tools Rate Thread

Converting from Decimal to Base-36 in Excel Formula

 
 
Jason Tram
Guest
Posts: n/a
 
      12th May 2011
Hi! Hoping someone can help with this...

I found this very nice formula in another post that converts a Base-36 # to decimal:
=IF(A1="","0",SUMPRODUCT(POWER(36,LEN(A1)-ROW(INDIRECT("1:"&LEN(A1)))),(CODE(UPPER(MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1)))-48*(CODE(MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1))<58)-55*(CODE(MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1))>64))))

Can someone write me the opposite code in a similar Excel formula format?
ie, converting a # as high as 999999999999999 (15 9's) to Base-36 ... I'm using web converters right now as an alternative and the Base-36 converted # is "9ugxnorjlr"

If the code, like above, can accommodate other Base-X conversion (by changing the "36"), that would be even better, thanks!

-Jason


 
Reply With Quote
 
 
 
 
isabelle
Guest
Posts: n/a
 
      12th May 2011
hi,

there is an example here:
http://www.freevbcode.com/ShowCode.asp?ID=6604

=ConvertBase10(A1,"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ")

Sub main()
Dim MyNumber As Double
MyNumber = 999999999999999#
MsgBox MyNumber & ": " & ConvertBase10(MyNumber, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ")
End Sub

Public Function ConvertBase10(ByVal d As Double, ByVal sNewBaseDigits As String) As String
Dim S As String, tmp As Double, i As Integer, lastI As Integer
Dim BaseSize As Integer
BaseSize = Len(sNewBaseDigits)
Do While Val(d) <> 0
tmp = d
i = 0
Do While tmp >= BaseSize
i = i + 1
tmp = tmp / BaseSize
Loop
If i <> lastI - 1 And lastI <> 0 Then S = S & String(lastI - i - 1, Left(sNewBaseDigits, 1)) 'get the zero digits inside the number
tmp = Int(tmp) 'truncate decimals
S = S + Mid(sNewBaseDigits, tmp + 1, 1)
d = d - tmp * (BaseSize ^ i)
lastI = i
Loop
S = S & String(i, Left(sNewBaseDigits, 1)) 'get the zero digits at the end of the number
ConvertBase10 = S
End Function


--
isabelle

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel error in converting decimal to fraction Raptor Microsoft Excel Discussion 3 25th Jul 2008 12:52 PM
formula for converting decimal to inch & fraction =?Utf-8?B?ZGF2ZXBhdHJvYg==?= Microsoft Excel Misc 1 31st Dec 2005 03:10 PM
Re: How do I convert numbers in Excel from Decimal to base 6 ? Ron Rosenfeld Microsoft Excel Misc 0 10th Sep 2004 02:30 PM
Re: How do I convert numbers in Excel from Decimal to base 6 ? Frank Kabel Microsoft Excel Misc 0 9th Sep 2004 10:41 PM
Converting an excel data base set up ........ BB Microsoft Access External Data 1 31st Mar 2004 04:30 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:34 AM.