Code

 
  VBScript Routines  
  Decimal to Binary
  Binary to Decimal
  Hex. to Decimal   Decimal to Hex.
 
JavaScript Routines
  setTimeout
  Rollovers
 
HTML
  Web Safe Colors
  Web Safe Color Picker

VBScript: Decimal to Hexadecimal Conversion

The Easy Way

VBScript has a function to convert Decimal to Hexadecimal. Here is an example of its use:

response.write Hex(13499)

The output from this function call would be:

34BB

The Hard Way

If you wanted to do it the hard way, you could. Here is an example. This function converts a decimal value to a string containing a hexadecimal respresentation of the value. It is limited to a maximum value of 65536 (FFFF in hex). This maximum can be changed by setting the intEXP initial value.

Function DecToHex(intDEC)
  dim strResult
  dim intValue
  dim intExp
  dim arrDigits

  arrDigits = array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F")

  strResult = ""

  intValue = intDEC
  intExp = 65536
  while intExp >= 1
    if intValue >= intExp then
      strResult = strResult & arrDigits(int(intValue / intExp))
      intValue = intValue - intExp * int(intValue / intExp)
    else
      strResult = strResult & "0"
    end if
    intExp = intExp / 16
  wend

  DecToHex = strResult
End Function

 

Tell me what you think