Home > How-To Library > Coding Basics
How to Convert Decimal to Hexadecimal
**************************************************************** * © 2007 CodeItBetter http://www.codeitbetter.com * * This notice MUST stay intact for legal use * **************************************************************** 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
If you would like to submit your code here please us. Do not forget to mention your name. We are always thankful to each and everyone of you who submitted their code here.