Code archives/Algorithms/Hex$ to Decimal
This code has been declared by its author to be Public Domain code.
Download source code
| |||||
This little Function will convert a string containing an hex value and return a decimal integer. Hex values do not need to be specially formatted. Ex: FF, fF, 0xff are OK. Non hex characters are simply ignored. | |||||
Function Dec(h$) t2$=Upper$(Trim$(h$)) d=0 For z=1 To Len(t2$) i=Instr("0123456789ABCDEF",Mid$(t2$,z,1)) If i>0 Then d=d*16+i-1 Next Return d End Function |
Comments
| ||
You saved me an hour of work with something very effective, thanks you a lot |
| ||
For BlitzMax, strict:Function Dec(h$) Local t2$=Upper$(Trim$(h$)) Local d=0 For Local z=1 To Len(t2$) Local i=Instr("0123456789ABCDEF",Mid$(t2$,z,1)) If i>0 Then d=d*16+i-1 Next Return d End Function |
| ||
For blitzmax you could just as well doPrint "$FF".ToInt() ;) |
| ||
Or this, if it's in a variable:Print ( "$" + myString ).ToInt() |
Code Archives Forum