Author Topic: Questions about GLBasic  (Read 10580 times)

Offline Slydog

  • Prof. Inline
  • *****
  • Posts: 932
  • KodeSource
    • View Profile
    • KodeSource
Re: Questions about GLBasic
« Reply #30 on: 2016-Aug-14 »
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!
« Last Edit: 2016-Aug-14 by Slydog »
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]

Offline Eric.Erpelding

  • Mc. Print
  • *
  • Posts: 32
    • View Profile
Re: Questions about GLBasic
« Reply #31 on: 2016-Aug-14 »
I wrote:
Quote
One 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.

Offline Leon

  • Mc. Print
  • *
  • Posts: 42
    • View Profile
Re: Questions about GLBasic
« Reply #32 on: 2016-Aug-14 »
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.