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
Is it really needed though ?
My routine (for hexadecimal) : http://www.glbasic.com/forum/index.php?topic=2859.msg20964#msg20964
Yap ! :D
Ok i know its not important and must not set to high priority and so on but why not implement this ?
decToHex is what I use and it's fine but need an update where the default length is max rather than trim.
What do you mean by that - the maximum output size can be changed
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.
Ah, right!
Righto, so update? ;)
Give this a try :
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
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
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.
But not with hex$ ill guess :nana:
Search the forum for hex$. I'm sure it exists, too.
As good TV cooks always seem to say, here's one I made earlier...
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$()...
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