469,358 Members | 1,682 Online

# Convert decimal to 36-base system 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.
decimal to base-36.
Can anyone help me with that?
May 12 '11 #1
4 8609 Rabbit
12,516 Expert Mod 8TB
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
1. 17(base 10) -> (base 16)
2.
3. 16^0 = 1
4. 16^1 = 16
5. 16^2 = 256
6.
7. 17 / 16^1 = 1.0625
8. 1 is the leftmost digit in base 16
9.
10. 17 - 1 * 16^1 = 1
11. 1 / 16^0 = 1
12.
13. 17 (Base 10) = 11 (Base 16)
May 12 '11 #2
Rolandas
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
1. =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
Rabbit
12,516 Expert Mod 8TB
There's no native function if that's what you're asking.
May 12 '11 #4
8,800 Expert 8TB
Here is a little Function that will convert any Positive Integer to a Base36 String:
Expand|Select|Wrap|Line Numbers
1. Function fBase36Encode(ByRef lngNumToConvert As Long) As String
2. 'Will Convert any Positive Integer to a Base36 String
3. Dim strAlphabet As String
4.
5. strAlphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
6.
7. If lngNumToConvert = 0 Then
8.   Base36Encode = "0"
9.     Exit Function
10. End If
11.
12. fBase36Encode = vbNullString
13.
14. Do While lngNumToConvert <> 0
15.   fBase36Encode = Mid(strAlphabet, lngNumToConvert Mod 36 + 1, 1) & fBase36Encode
16.     lngNumToConvert = lngNumToConvert \ 36
17. Loop
18. End Function
May 13 '11 #5

 13 posts views Thread by Jason | last post: by 5 posts views Thread by Ray | last post: by 13 posts views Thread by muss | last post: by 5 posts views Thread by lathasree | last post: by 6 posts views Thread by sweeet_addiction16 | last post: by 1 post views Thread by karanbikash | last post: by 2 posts views Thread by nirmalsingh | last post: by 1 post views Thread by Vitaliy | last post: by 1 post views Thread by pankajprakash | last post: by reply views Thread by ioana budai | last post: by 1 post views Thread by CARIGAR | last post: by reply views Thread by zhoujie | last post: by reply views Thread by SioSio | last post: by reply views Thread by suresh191 | last post: by 2 posts views Thread by mgbsher | last post: by 1 post views Thread by dDule | last post: by 1 post views Thread by Marylou17 | last post: by 2 posts views Thread by Darius9023 | last post: by