Hex2Dec Function:
Converts an Hexadecimal value to Decimal.
Description:
Hex2Dec Function converts an Hexadecimal value to Decimal.
Syntax:
decimal = Hex2Dec(hexValue)
Details:
'--- input: a Hex string '--- return: '--- -2 null string '--- -1 error (non-hex char) '--- >= 0 the converted value
Example:
<%
Hex2Dec("1afc2b") '--- returns: 1768491
Hex2Dec("FF") '--- returns: 255
%>
ASP Source Code:
<%
Function Hex2Dec(ByVal inHex) Dim loRegExp : Set loRegExp = New RegExp Dim nVal : nVal = 0 Dim i, Hex2Dgt If ( inHex="") Then Hex2Dec = -2 Exit Function End If loRegExp.Pattern = "[^0-9A-Fa-f]" If (loRegExp.Test(inHex)) Then Hex2Dec = -1 Exit Function End If For i=1 to Len(inHex) If (Mid(inHex,i,1) <= "9" ) Then Hex2Dgt = Asc(Mid(inHex, i, 1)) - Asc("0") Else Hex2Dgt = Asc(uCase(Mid(inHex, i, 1))) - Asc("A") + 10 End If nVal = nVal * 16 + Hex2Dgt Next Hex2Dec = nVal set loRegExp = Nothing End Function
%>
|