Hexadecimal to Decimal
Posted In:
PowerScript
.
By popo
Here's function to convert Hexadecimal number to Decimal number
/**********************************************/
/* public long uf_Hex2Dec ( string as_Hex ) */
/**********************************************/
CONSTANT STRING ls_HexSet = "0123456789ABCDEF"
STRING ls_Hex, ls_Bit
LONG ll_Div, ll_RetVal = 0
INTEGER li_C, li_Len, li_Pos
BOOLEAN lb_Error = FALSE
ls_Hex = Upper( as_Hex )
IF NOT IsNull( ls_Hex ) AND ls_Hex <> "" THEN
li_Len = Len( ls_Hex )
FOR li_C = 1 TO li_Len
ls_Bit = Mid( ls_Hex, li_C, 1 )
li_Pos = Pos( ls_HexSet, ls_Bit )
IF li_Pos = 0 THEN
lb_Error = TRUE
ELSE
ll_RetVal += ( ( li_Pos - 1 ) * ( 16 ^ ( li_Len - li_C ) ) )
END IF
NEXT
IF lb_Error THEN ll_RetVal = 0
END IF
RETURN ll_RetVal