Here are a couple of snippets that will help you convert a hexadecimal number to decimal, and vice-versa.
T-SQL SELECT 'Int -> Hex' SELECT CONVERT(VARBINARY(8), 16777215) SELECT 'Hex -> Int' SELECT CONVERT(INT, 0xFFFFFF) |
VBScript VBScript has a built-in dec->hex function called hex. To do the opposite, you use a concatenation of "&H" and the hex value.
<% Response.Write "<hr>Long -> Hex, VBScript<p>" DecVal = 16777215 Response.Write Hex(DecVal) Response.Write "<hr>Hex -> Long, VBScript<p>" HexVal = "FFFFFF" Response.Write CLng("&H" & HexVal) %> |
JScript And here it is in JScript, which uses toString (with a radix of 16) to get hex from decimal, and parseInt which has the ability to determine the integer value of a hex:
<script language=jscript runat=server> Response.Write("<hr>Dec -> Hex, JScript<p>"); DecVal = 16777215; Response.Write(DecVal.toString(16).toUpperCase()); Response.Write("<hr>Hex -> Dec, JScript<p>"); HexVal = "FFFFFF"; Response.Write(parseInt("0x"+HexVal)); </script> |