Questions about GLBasic

Previous topic - Next topic

Slydog

#30
Here's a Hex to Int conversion function I found in my old code:

Code (glbasic) Select
FUNCTION HexToInt%: hex$
LOCAL i%=0
LOCAL j%=0
LOCAL loop%

FOR loop = 0 TO LEN(hex$)-1
i = ASC(MID$(hex$, loop, 1)) - 48
IF i > 9
DEC i, 7
ENDIF

j = j * 16
j = bOR(j, bAND(i, 15))
NEXT

RETURN j
ENDFUNCTION


[Edit] Ha, apparently I got my code from MrTAToad in that link posted by dreamerman!
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]

Eric.Erpelding

I wrote:
QuoteOne has to create a function containing INLINE code to call the sscanf function that will do the conversion.
I should have said that one "could" create a function that calls scanf from within INLINE code.

Of course, as has been pointed out by previous posters, one can create a FUNCTION containing pure GLBASIC code that will do the same Hex to Dec conversion.

Leon

Well, INLINE really seems to be useful at times. I doubt that I will have to use it though.
However, I really like the idea behind it.