|
Gilbert Beginner
Joined: 10 Oct 2000 Posts: 11 Location: Germany
|
Posted: Sun May 23, 2004 10:43 am
Request: DEC2HEX |
Hi there,
it is possible to add this function?
Or anyone else can help me, to get this work [?]
Regaards,
Christian - going crazy |
|
|
|
Rorso Wizard
Joined: 14 Oct 2000 Posts: 1368
|
Posted: Sun May 23, 2004 11:46 am |
quote: Originally posted by Gilbert
Hi there,
it is possible to add this function?
Or anyone else can help me, to get this work [?]
Regaards,
Christian - going crazy
Hello,
Adding hex support isn't too difficult. Here is how to do it:
#VAR hex {0|1|2|3|4|5|6|7|8|9|A|B|C|D|E|F}
#VAR toHex {%if( %1<>0, %concat( @toHex(%eval(%1 / 16)), %item( @hex, %eval( %mod( %1, 16)+1))), "")}
Using this you could add binary support too:
#VAR toBin {%if( %1<>0, %concat( @toBin(%eval(%1 / 2)), %item( @bin, %eval( %mod( %1, 2)+1))), "")}
#VAR bin {0|1}
Example:
#echo @toHex(20)
> 14
#echo @toHex(2000)
> 7D0
#echo @toBin(20)
> 10100 |
|
|
|
Gilbert Beginner
Joined: 10 Oct 2000 Posts: 11 Location: Germany
|
Posted: Sun May 23, 2004 12:00 pm |
Hi Rorso,
many many thanx to you. i think, i should think easier....
Christian |
|
|
|
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Sun May 23, 2004 5:15 pm |
Should use the #FUNCTION command for this.
#VAR toHex {%if( %1<>0, %concat( @toHex(%eval(%1 / 16)), %item( @hex, %eval( %mod( %1, 16)+1))), "")}
#VAR toHex
Displays:
Variable: toHex ............. @toHex(%eval(%1 / 16))0
#FUN toHex {%if( %1<>0, %concat( @toHex(%eval(%1 / 16)), %item( @hex, %eval( %mod( %1, 16)+1))), "")}
#VAR toHex
Displays:
Variable: toHex ............. %if( %1<>0, %concat( @toHex(%eval(%1 / 16)), %item( @hex, %eval( %mod( %1, 16)+1))), "")
Nice work on the functions. |
|
|
|
Rorso Wizard
Joined: 14 Oct 2000 Posts: 1368
|
Posted: Sun May 23, 2004 5:44 pm |
quote: Originally posted by LightBulb
Should use the #FUNCTION command for this.
#VAR toHex {%if( %1<>0, %concat( @toHex(%eval(%1 / 16)), %item( @hex, %eval( %mod( %1, 16)+1))), "")}
#VAR toHex
Displays:
Variable: toHex ............. @toHex(%eval(%1 / 16))0
#FUN toHex {%if( %1<>0, %concat( @toHex(%eval(%1 / 16)), %item( @hex, %eval( %mod( %1, 16)+1))), "")}
#VAR toHex
Displays:
Variable: toHex ............. %if( %1<>0, %concat( @toHex(%eval(%1 / 16)), %item( @hex, %eval( %mod( %1, 16)+1))), "")
Ah so that is the difference between #func and #var .
quote:
Nice work on the functions.
Thanks. I discovered an annoying bug though:
@toHex(0) -> ""
It happens because the end case of the recursion has to be the empty string or you get 0 appended to the outcome. Luckily that is easy to solve using a wrapper function.
Func: toHex
code: %if( %1<>0, @realToHex(%1), 0)
Func: realToHex
code: %if( %1<>0, %concat( @realToHex(%eval(%1 / 16)), %item( @hex, %eval( %mod( %1, 16)+1))), "")
#echo @toHex(0) -> 0 |
|
|
|
Guede Wanderer
Joined: 30 Nov 2003 Posts: 65 Location: United Kingdom
|
Posted: Sun May 23, 2004 7:08 pm |
Just as a side note here, if you are confident with COM scripting (which I'm not) and VB Script you could use the VBScript Hex() function to do it for you.
-G- |
|
|
|
Rorso Wizard
Joined: 14 Oct 2000 Posts: 1368
|
Posted: Sun May 23, 2004 10:26 pm |
quote: Originally posted by Guede
Just as a side note here, if you are confident with COM scripting (which I'm not) and VB Script you could use the VBScript Hex() function to do it for you.
-G-
That's clever. You can use the %mss function to call a VBScript function like this:
#echo %mss("hex(4000)", "vbscript") |
|
|
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|