GLBasic forum

Main forum => GLBasic - en => Topic started by: Marmor on 2012-Nov-30

Title: Ähem...
Post by: Marmor on 2012-Nov-30
is Glb really the only Basic without an hex$ or bin$ inline Function.
He Gernot come on  this is standard !
and dont say use your own Function  :D
Title: Re: Ähem...
Post by: MrTAToad on 2012-Dec-01
Is it really needed though ?

My routine (for hexadecimal) : http://www.glbasic.com/forum/index.php?topic=2859.msg20964#msg20964
Title: Re: Ähem...
Post by: Marmor on 2012-Dec-01
Yap !   :D 

Ok i know its not important and must not set to high priority and so on but why not implement this ?

Title: Re: Ähem...
Post by: matchy on 2012-Dec-01
decToHex is what I use and it's fine but need an update where the default length is max rather than trim.
Title: Re: Ähem...
Post by: MrTAToad on 2012-Dec-01
What do you mean by that - the maximum output size can be changed
Title: Re: Ähem...
Post by: matchy on 2012-Dec-03
I mean trimming leading hex zeros. I've had to ad code to do that to handle multiple lengths for example; 0xAB and 0xABCD as 0x0000AB and 0x00ABCD.
Title: Re: Ähem...
Post by: MrTAToad on 2012-Dec-03
Ah, right!
Title: Re: Ähem...
Post by: matchy on 2012-Dec-03
Righto, so update?  ;)
Title: Re: Ähem...
Post by: MrTAToad on 2012-Dec-04
Give this a try :

Code (glbasic) Select
FUNCTION decToHex$:value%,length%=4
LOCAL digit%
LOCAL temp%
LOCAL result$

IF length%<=0
RETURN "0"
ENDIF

result$=""
FOR digit%=length% TO 1 STEP -1
IF value%=0 THEN BREAK

temp%=MOD(value%,16)
IF temp%<10
result$=CHR$(temp%+48)+result$
ELSE
result$=CHR$((temp%-10)+65)+result$
ENDIF

value%=value%/16
NEXT

RETURN result$
ENDFUNCTION
Title: Re: Ähem...
Post by: Moru on 2012-Dec-04
Quote from: Marmor on 2012-Nov-30
is Glb really the only Basic without an hex$ or bin$ inline Function.
He Gernot come on  this is standard !
and dont say use your own Function  :D

Hmm, it can't be the only one. I specifically remember writing those functions as exercises in school when I was young.  =D
Title: Ähem...
Post by: Kitty Hello on 2012-Dec-04
A hint. But I'll do this better. You can do any file operation with:
mem:/xxxxxx
Where xxxxx is a 4byte pointer to your memory. At that address the first 4 bytes are the lenght, then the data. It's awkard, but would work with loadsprite and such.
Title: Re: Ähem...
Post by: Marmor on 2012-Dec-04
But not with hex$ ill guess  :nana:

Title: Ähem...
Post by: Kitty Hello on 2012-Dec-04
Search the forum for hex$. I'm sure it exists, too.
Title: Re: Ähem...
Post by: bigsofty on 2012-Dec-04
As good TV cooks always seem to say, here's one I made earlier...

Code (glbasic) Select
FUNCTION Hex$:num%
LOCAL h$="0123456789ABCDEF", num$
REPEAT
num$=MID$( h$, bAND(num%,0xF) ,1)+num$
num%=ASR(num%,4)
UNTIL num%=0
RETURN num$
ENDFUNCTION


And a little edit of the one above provides a Bin$()...

Code (glbasic) Select
FUNCTION Bin$:num%
LOCAL B$="01", num$
REPEAT
num$=MID$( B$, bAND(num%,0x1) ,1)+num$
num%=ASR(num%,1)
UNTIL num%=0
RETURN num$
ENDFUNCTION