From: "Gabriel Diaz" <gabidiaz@gmail.com>
To: "Fans of the OS Plan 9 from Bell Labs" <9fans@cse.psu.edu>
Subject: Re: [9fans] awk: hex numbers? (and leak(1))
Date: Wed, 20 Sep 2006 15:34:20 +0200 [thread overview]
Message-ID: <82c890d00609200634u42901f17pb537f5b92a34c556@mail.gmail.com> (raw)
In-Reply-To: <200609201034.k8KAY0w20632@zamenhof.cs.utwente.nl>
hello
may be this help you:
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;
}
then just sum=todec(hex1)+todec(hex2);
if you do not go beyond int it should work.
slds.
gabi
On 9/20/06, Axel Belinfante <Axel.Belinfante@cs.utwente.nl> wrote:
> is there a way to use awk to sum hex values?
> i.e. I want to sum values in the 3rd column of
>
> block 0x000af9a8 0x00000040 0x0001ddf3 0x00000000
> block 0x000afd88 0x00000040 0x0001ddf3 0x00000000
>
> I have tried to make awk use an external program
> to do the hex-to-dec conversion, but that was very
> slow (probably due to many page faults).
> (in the end I resorted to perl...)
>
>
>
> context:
>
> I've been fiddling with leak(1) to make it print
> an overview of how much memory is allocated where,
> as in:
>
> location total calls
> amount
> allocated
>
> src(0x0001d8f1); // 247648 20
> src(0x000067f8); // 24256 59
> src(0x0001da70); // 15760 6
> src(0x000128ac); // 8256 1
> src(0x000210f8); // 4128 66
> src(0x00014bc2); // 3648 57
> [...]
> src(0x00006586); // 64 1
> src(0x00011a50); // 64 1
> src(0x000067c7); // 64 1
> src(0x0001ca32); // 32 1
> // 326544
>
>
> I found it quite useful to get insight in where
> the memory goes (even when it is not leaked) -
> but maybe we already have this functionality
> somewhere, and I missed it?
>
> Axel.
>
next prev parent reply other threads:[~2006-09-20 13:34 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-09-20 10:33 Axel Belinfante
2006-09-20 13:34 ` Gabriel Diaz [this message]
2006-09-20 13:58 ` Axel Belinfante
2006-09-20 20:20 ` Russ Cox
2006-09-20 20:29 ` Gabriel Diaz
2006-09-21 22:41 ` Axel Belinfante
2006-09-21 23:02 ` Russ Cox
2006-09-22 9:57 ` Axel Belinfante
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=82c890d00609200634u42901f17pb537f5b92a34c556@mail.gmail.com \
--to=gabidiaz@gmail.com \
--cc=9fans@cse.psu.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).