How to Convert Decimal to Hexadecimal
Posted on August 17, 2011
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 31 32 33 34 35 36 37 38 39 40 41 | 'Coding Basics - How to Convert Decimal to Hexadecimal Public Function ConvertDecimalToHexadecimal(Value As Double) As String Dim iVal#, temp#, ret%, i%, Str$ Dim BinVal$() iVal = Value Do temp = iVal / 16 ret = InStr(temp, ".") If ret > 0 Then temp = Left(temp, ret - 1) End If ret = iVal Mod 16 ReDim Preserve BinVal(i) BinVal(i) = NoToHex(ret) i = i + 1 iVal = temp Loop While temp > 0 For i = UBound(BinVal) To 0 Step -1 Str = Str + CStr(BinVal(i)) Next ConvertDecimalToHexadecimal = Str End Function Private Function NoToHex(i As Integer) As String Select Case i Case 0 To 9 NoToHex = CStr(i) Case 10: NoToHex = "A" Case 11: NoToHex = "B" Case 12: NoToHex = "C" Case 13: NoToHex = "D" Case 14: NoToHex = "E" Case 15: NoToHex = "F" End Select End Function |