Page 1 of 1
[Implemented] Val function to work with hexadecimal strings
Posted: Thu Sep 25, 2003 7:20 am
by AngelSoul
Example:
a$ = "$10"
debug Val(a$)
;would be cool if it returns 16 instead of 0
Re: Val function to work with hexadecimal in strings
Posted: Thu Sep 25, 2003 8:46 am
by PB
In the meantime, try this:
Code: Select all
Procedure hex2dec(h$)
h$=Trim(UCase(h$)) : If Left(h$,1)="$" : h$=Mid(h$,2,999) : EndIf
For r=1 To Len(h$)
d<<4 : a$=Mid(h$,r,1)
If Asc(a$)>60
d+Asc(a$)-55
Else
d+Asc(a$)-48
EndIf
Next
ProcedureReturn d
EndProcedure
a$="$10"
Debug hex2dec(a$)
Re: Val function to work with hexadecimal in strings
Posted: Thu Oct 11, 2007 12:07 am
by PB
@Fred: Please make a native hex2dec command soon. Please.

Posted: Thu Oct 11, 2007 12:50 am
by Kaeru Gaman
I can understand that the native Val() only supports decimal.
it's for all the performance reasons we love PureBasic for...
same like why we have not only Str() but also StrF() and StrQ() and StrD()...
but I agree, a native ValHex(Hex$) would be fine.
Posted: Thu Oct 11, 2007 10:16 am
by #NULL
i would make use of a native one too.
sometimes i even used a..
val.l = valBin(binStr.s)
..but mostly for debugging or testing stuff.
Posted: Thu Oct 11, 2007 12:41 pm
by nco2k
yes fred, please add a Hex2Dec() soon, its been a looooong time now.
c ya,
nco2k
Posted: Sun Jan 27, 2008 4:38 pm
by Thalius