440,686 Members | 1,603 Online Need help? Post your question and get tips & solutions from a community of 440,686 IT Pros & Developers. It's quick & easy.

# Convert decimal to 36-base system

 P: 10 Hi, Can anyone help me? I need a code in VBA which would convert decimal numbers to the other system bases on number 36. e.g. in this page http://www.translatorscafe.com/cafe/units-converter/numbers/calculator/octal-to-decimal/ decimal to base-36. Can anyone help me with that? May 12 '11 #1
4 Replies

 Expert Mod 10K+ P: 12,374 First you find the highest power of 36 that isn't larger than the number you're trying to convert. Then you divide by that. The whole number from that result gives you the leftmost digit. You take that whole number, multiply by the power of 36 and subtract it from the number you're converting. Then you repeat to get the rest of the digits. Expand|Select|Wrap|Line Numbers 17(base 10) -> (base 16)   16^0 = 1 16^1 = 16 16^2 = 256   17 / 16^1 = 1.0625 1 is the leftmost digit in base 16   17 - 1 * 16^1 = 1 1 / 16^0 = 1   17 (Base 10) = 11 (Base 16) May 12 '11 #2

 P: 10 Thanks for the answer. The algorithm is clear. Another question: Perhaps there is a function in excel which converts from base 10 to base 36? This function is opposite. It converts numbers from base 36 to base 10: Expand|Select|Wrap|Line Numbers =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)))) May 12 '11 #3

 Expert Mod 10K+ P: 12,374 There's no native function if that's what you're asking. May 12 '11 #4

 Expert 5K+ P: 8,668 Here is a little Function that will convert any Positive Integer to a Base36 String: Expand|Select|Wrap|Line Numbers Function fBase36Encode(ByRef lngNumToConvert As Long) As String 'Will Convert any Positive Integer to a Base36 String Dim strAlphabet As String   strAlphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"   If lngNumToConvert = 0 Then   Base36Encode = "0"     Exit Function End If   fBase36Encode = vbNullString   Do While lngNumToConvert <> 0   fBase36Encode = Mid(strAlphabet, lngNumToConvert Mod 36 + 1, 1) & fBase36Encode     lngNumToConvert = lngNumToConvert \ 36 Loop End Function May 13 '11 #5 