Is there a function for converting a base 32 into a base 10???????
Is there a function for converting a base 32 into a base 10???????
NO. i doubt it.
but try some basic math functions, or a combo of them
I don't even know where to start
Did you really mean Base 2 (not Base 32).
do you know what base 10 IS?? if you do, you can write a simple function in vba to work it.
first of all, how are your numbers stored?? as actuals or numbers written with "10" as a following subscript?? if they are ACTUALS, here is an example of a conversion from base 32 to 10:
e.g. ---- 200 (base 32) = (2 * 32^2) + (0 * 32^1) + (0 * 32^0) = whatever + 0 + 0 = whatever
e.g. ---- 200 (base 10) = (2 * 10^2) + (0 * 10^1) + (0 * 10^0) = 200 + 0 + 0 = 200
so that's where you start. follow?? I could help ya write it, but I'm busy at the moment. But that's how BASE numbers work!
Thank you for the explanation, but the numbers that I have are numbers and letters.
For example, 3LNJ8L is 123456789.
That is where I am getting confused.
well I have no idea what that means sir. If it's mathematically based, I don't know what the conversion code is. but if you already have an example of it, as you just showed us, then that must mean that you already have the numerical conversions for all of your alpha-numeric strings?? If you've got letters higher than "F" then obviously it's not hexidecimal based.
if you do, then you can simply use the math I already gave you. right??
All of the below is based on me working out how 3LNJ8L works into 123456789. If I made a math mistake then the below is rubbish.
If I am doing this correctly Base 32 means using numbers 0 - 9 and letters A - V (Base 36 = 0 - 9 and A - Z). Therefore 0 - 9 represent 0 - 9, A = 10, B = 11, C = 12 and so forth until V = 31.
A. Thus 3LNJ8L works out to represent [3] [21] [23] [19] [8] and [21].
B. Each position of 3LNJ8L represents a power of 32:
Far right digit(L) = 32^0 = 1
Next digit to the left (8) = 32^1 = 32
Next digit to the left (J) = 32^2 = 1,024
Next digit to the left (N) = 32^3 = 32,768
Next digit to the left (L) = 32^4 = 1,048,576
Next digit to the left (3) = 32^5 = 33,554,432
C. So now multiply:
3 * 33,554,432 = 100,663,296
[L] 21 * 1,048,576 = 22,020,096
[N] 23 * 32,768 = 753,664
[J] 19 * 1024 = 19,456
8 * 32 = 256
[L] 21 * 1 = 21
---------------
If my math was correct and there are no typos then the above should add up to 123,456,789. (I have no idea how the text formatting is going to turn out when I hit "Submit Reply". I didn't know how to do it.)
Is that helpful at all?
Edit: The text formatting didn't turn out exactly like I wanted it, but it still isn't too bad.
Last edited by nicknameoscar; 05-31-2011 at 05:46 PM. Reason: commenting about how format turned out
I doubt I am good enough yet to turn out a function like that without considerable effort.
To be totally honest, I had never dealt with anything other than binary, octal or hex and I just wanted to see if I could figure out how Base 32 worked.
I will take a look at designing a function when I am not so tired. It sounds like a fun challenge.
well this is actually NOT tough.
first of all, you have to figure out what you want as the end result. for instance, does the end result change or not?? E.G. -
111 base 32 does NOT equal 111 base 10
so if you want to keep your RESULT value the same in terms of it's actual number value, all you need to do is perform the drawn out calculations we've already done. BASE 10 is nothing more than the number itself after the base 32 calculations are performed.
so for instance, to convert a BASE 32 number to BASE 10 in vba, all you need is this:
hence, my example of 200 checks out fine. the answer is 2048.Code:Function to10(base32 As String) Dim base As Long Dim length As Long Dim pos As Long Dim temp As Long base = Len(base32) - 1 length = Len(base32) pos = 1 While base >= 0 temp = temp + (CLng(Mid(base32, pos, 1)) * (32 ^ (base))) base = base - 1 pos = pos + 1 Wend to10 = temp End Function
200 BASE 32 = 2048 BASE 10 with the above function, and with my previous post. Again, the fact that base 10 numbers are their actual values was the thing that was missed here I think. It's not difficult to convert to BASE 10. The difficult part would be converting from 32 to something other than 10. That would require much more code.![]()
Thanks everybody for the feedback. I think the VBA that was given will work fine for my use. thanks again
ajetrumpet,
I installed your function and keep getting an error. When I go to the error the line temp = temp + (CLng(Mid(base32, pos, 1)) * (32 ^ (base)))
Is highlighted.
I put the function in a new moduale and am using the function in an unbound text box. however, It wont run. Am I doing something wrong?
PMFJI,
The problem here is that for any base greater than 10 (decimal), the position in the number is represented by a letter. The letter must be converted to a decimal number; ie in hexadecimal, "10" (decimal) is represented by the letter "A" (hex).I installed your function and keep getting an error. When I go to the error the line temp = temp + (CLng(Mid(base32, pos, 1)) * (32 ^ (base)))
Is highlighted.
I modified the code ajetrumpet provided. To call the function you would use:
= toDec("3LNJ8L", 32) 'the letters are case insensitive
This should be able to convert up to base 35 (uses letters A-Z)Code:Function toDec(pNumber As String, pBase As Integer) As Double Dim base As Long Dim length As Long Dim pos As Long Dim temp As Long Dim MyValue 'varient - to hold letters Dim tmp As Long Dim MaxLetter As Integer Dim i As Integer toDec = 0 base = Len(pNumber) - 1 length = Len(pNumber) pos = 1 ' is pNumber within base range MaxLetter = pBase - 1 For i = 1 To length If Asc(Mid(pNumber, i, 1)) - 55 > MaxLetter Then MsgBox "'" & pNumber & "' is not a base" & pBase & " number" Exit Function End If Next While base >= 0 MyValue = Mid(pNumber, pos, 1) ' A = ascii 65 and Z = ascii 90 'convert letter to value If Asc(UCase(MyValue)) >= 65 And Asc(UCase(MyValue)) <= 90 Then tmp = CLng(Asc(UCase(MyValue)) - 55) Else tmp = CLng(MyValue) End If temp = temp + (tmp * (pBase ^ (base))) base = base - 1 pos = pos + 1 Wend toDec = temp End Function