hello
sorry i mixed with bc syntax.
function is the right keyword.
gabi
On 9/20/06, Russ Cox <[EMAIL PROTECTED]> wrote:
> define todec(str) {
> hstr="1234567890ABDCEF";
> res=0;
> n=split(str,digit,"");
>
> for(i=1;i<=n;i++) {
> num=index(hstr,digit[i])-1;
> res=res+(num*16^(n-i));
> }
>
> return res;
> }
Here's an alternate version.
Among other things my awk doesn't seem to know about "define".
BEGIN {
for(i=0; i<16; i++)
_unhex[sprintf("%x", i)] = _unhex[sprintf("%X", i)] = i
}
function unhex(s, i, v) {
v = 0
for (i=1; i<=length(s); i++)
v = v*16 + _unhex[substr(s,i,1)]
return v
}
{print unhex($1)}
Russ