473,324 Members | 2,581 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Convert decimal to 36-base system

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 9657
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
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
ADezii
8,834 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

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: Jason | last post by:
Could someone here show me how I would write a vb program to convert decimal ip address to binary? For example a small form with a convert button and a label for the result and a textbox for the...
5
by: Ray | last post by:
I have a table with some audit date and time columns. Problem is the developer who stored the data left them as DECIMAL type instead of DATE and TIME. Is there a way I can convert the DECIMAL type...
13
by: muss | last post by:
how to convert decimal number in a hexadecimal number using C? Please help me. Thanks.
5
by: lathasree | last post by:
Hi, this is sreelatha give a c progrm to convert decimal to binary.... thank u....
6
by: sweeet_addiction16 | last post by:
hello Im writin a code in c... can sum1 pls help me out in writing a c code to convert decimalnumber to hexadecimal number.The hexadecimal number generated has to be an unsigned long.
1
by: karanbikash | last post by:
Hi , I have a requirement where in I need to display the decimal value of 0.00 as '######.00' SELECT case when DECIMAL(AMT_CHEQUE,31,2) = 0.00 THEN 9999999999999.9999999 ELSE ...
2
nirmalsingh
by: nirmalsingh | last post by:
Hai all, i want to convert decimal to time. for example if i have decimal number 09.6 then i need it as 10.00 and also decimal 10.118 as 11.58. How to convert this? Thanx in advance with Cheers...
1
by: Vitaliy | last post by:
Hi I got this wired exception periodically (Python 2.5, Django based application) what does it mean ?
1
by: pankajprakash | last post by:
Hi, I have a decimal number. I need to convert this decimal value to exponential value. I have a vb.net code to convert from decimal to exponential value is Format(100000, #.0#E-##) . When I run this...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.