This implementation uses a Prototype to ensure the routine gets a ascii hex string.
And should therefore produce same result wether Unicode is enabled or not in your program.
(If anyone knows a better way, please reply...)
Code: Select all
Prototype.q _ValH(*hex.p-ascii,len.l)
Procedure.q _ValH(hex,len)
Protected result.l,a.l,b.l
If len>0 And len<16
b=0
While len
len-1
a=PeekB(hex+len)
If a<58
a-48
Else
a-55
EndIf
result=(a<<b)+result
b+4
Wend
EndIf
ProcedureReturn result
EndProcedure
ValH._ValH=@_ValH()
test$="567587"
time=ElapsedMilliseconds()
loop=9999 ;9999=10000 loops
For x=0 To loop
num=ValH(@test$,Len(test$))
Delay(0) ;to avoid hogging the cpu (OS multitasking friendly)
Next
time=ElapsedMilliseconds()-time
MessageRequester("Elapsed time: x"+Str(loop+1),Str(time)+"ms",#MB_ICONINFORMATION)
;Same as above, but hogs the cpu
time=ElapsedMilliseconds()
For x=0 To loop
num=ValH(@test$,Len(test$))
Next
time=ElapsedMilliseconds()-time
MessageRequester("Elapsed time: x"+Str(loop+1),Str(time)+"ms",#MB_ICONINFORMATION)