How to Convert Hexadecimal to Decimal
Posted on January 4, 2009
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | 'Coding Basics - How to Convert Hexadecimal to Decimal Public Function ConvertHexadecimalToDecimal(BinVal As String) As String Dim iVal#, temp#, i%, Length% Length = Len(BinVal) For i = 0 To Length - 1 temp = HexToNo(Mid(BinVal, Length - i, 1)) iVal = iVal + (temp * (16 ^ i)) Next i ConvertHexadecimalToDecimal = iVal End Function Private Function HexToNo(i As String) As Integer Select Case i Case "0", "1", "2", "3", "4", "5", "6", "7", "8", "9": HexToNo = CInt(i) Case "A", "a": HexToNo = 10 Case "B", "b": HexToNo = 11 Case "C", "c": HexToNo = 12 Case "D", "d": HexToNo = 13 Case "E", "e": HexToNo = 14 Case "F", "f": HexToNo = 15 End Select End Function |