Hexidecimal to decimal
<< Back
There are many ways to convert a hex string into decimal number. I am presenting two different versions here.
- Version 1 relies on
Set_StrictEval to FALSE. StructEval is set to TRUE by default for all WebApps.
- Version 2 will work on all DF/VDF version.
Function HexToInt Global String sNum Returns Integer // Version 1
Function_Return (Integer("$"+sNum))
End_Function
Function HexToInt Global String sNum Returns Integer // Version 2
Integer iLength iDigit iNum iPower
Move (Length(sNum)) to iLength
Move 1 to iPower
Move 0 to iNum
While (iLength>0)
Move (Ascii(Mid(sNum,1,iLength))) to iDigit
Subtract (If(iDigit>57,55,48)) From iDigit
Add (iDigit*iPower) to iNum
Move (iPower*16) to iPower
Decrement iLength
Loop
Function_Return iNum
End_Function // HexToInt