Convert Hexadecimal number Larger than 10 digits
Hi,
I'm new to Excel VBA, can anyone help me with converting large Hexadecimal Number in Excel 2007.
I've used the following code from this forum, it converts but not absolutely accurately:
code:
Public Function HexToDec(Hex As String) As Double
Dim I As Long
Dim j As Variant
Dim k As Long
Dim n As Long
Dim HexArray() As Double
n = Len(Hex)
k = -1
ReDim HexArray(1 To n)
For I = n To 1 Step -1
j = Mid(Hex, I, 1)
k = k + 1
Select Case j
Case 0 To 9
HexArray(I) = j * 16 ^ (k)
Case Is = "A"
HexArray(I) = 10 * 16 ^ (k)
Case Is = "B"
HexArray(I) = 11 * 16 ^ (k)
Case Is = "C"
HexArray(I) = 12 * 16 ^ (k)
Case Is = "D"
HexArray(I) = 13 * 16 ^ (k)
Case Is = "E"
HexArray(I) = 14 * 16 ^ (k)
Case Is = "F"
HexArray(I) = 15 * 16 ^ (k)
End Select
Next I
HexToDec = Application.WorksheetFunction.Sum(HexArray)
End Function
The above code gives the output as "1394546016882220" in Excel to the input Hexa Value "04F4550BF58E28", whereas the correct answer is "1394546016882216".
Please help.