|
Post by MadModder on Aug 19, 2006 11:29:02 GMT -5
I have this hexadecimal to decimal conversion sub:
11010 l=len(hex$):dec=0 11020 fora=1tol 11030 b=asc(mid$(hea$,a,1)) 11040 ifb>47andb<58thendec=dec+(b-48)*(16^(l-a)) 11050 ifb>64andb<71thendec=dec+(b-55)*(16^(l-a)) 11060 next 11070 return But it's painfully slow. Are there better ways to do this, in basic?
|
|
|
Post by gmoon on Aug 19, 2006 12:51:10 GMT -5
I'm sure someone's done this efficiently--
Just my two cents: Couldn't you remove the test for decimal #s?--
Test for A-F, everything else is decimal, just subtract 48 from those, then do your multipiers, etc.
You don't check for valitity (0-9,A-F) with this routine, so I'm assuming the input is OK.
|
|
|
Post by MadModder on Aug 19, 2006 13:14:21 GMT -5
Ok, now it's like this (I remembered that only the two first characters of a variable name is used) 11010 l=len(hx$):dc=0 11020 fora=1tol 11030 b=asc(mid$(hx$,a,1))-48 11040 ifb>9thenb=b-7 11050 dc=dc+b*(16^(l-a)) 11060 next 11070 return But it's still as slow as before.
|
|
|
Post by gmoon on Aug 19, 2006 13:35:43 GMT -5
I dunno-- concatenate a few lines: xxx10 + xxx20, xxx30 + xxx40, xxx50, 60 + 70. Move subroutine to beginning of code. Using a lookup table (array), instead of computation, would help. Or punt -- AustroSpeed. Or write in ML.
|
|
|
Post by MadModder on Aug 19, 2006 13:58:26 GMT -5
Now I did this 1 l=len(hx$):dc=0:fora=1tol:b=asc(mid$(hx$,a,1))-48:ifb>9thenb=b-7 2 dc=dc+b*(16^(l-a)):next:return But I could not notice any difference. Oh well... I am going to austrospeed it when I'm all done. I think.
|
|