From: george anzinger <george@mvista.com>
To: Linus Torvalds <torvalds@transmeta.com>
Cc: Jakob Kemi <jakob.kemi@telia.com>, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] hex <-> int conversion routines.
Date: Tue, 19 Feb 2002 12:29:53 -0800 [thread overview]
Message-ID: <3C72B5C1.2D339F9B@mvista.com> (raw)
In-Reply-To: <Pine.LNX.4.33.0202191000340.26476-100000@home.transmeta.com>
Linus Torvalds wrote:
>
> On Tue, 19 Feb 2002, Jakob Kemi wrote:
> >
> > I also added three other hex-functions that can replace a lot of duplicated code.
> >
> > int hexint_nibble (char x); // hex digit to int.
> > int hexint_byte (const char *src); // hex digit-pair to int.
> > char inthex_nibble (int x); // int to hex digit.
> > void inthex_byte (int x, char* dest); // int to hex digit pair.
>
> Is there any reason to do all of this?
>
> I suspect 99% of all users can (and probably should) be replaced with
> "sscanf()" instead. Which does a lot more, of course, and is not the
> fastest thing out there due to that, but anybody who does hex->int
> conversion inside some critical loop is just crazy.
>
> Linus
>
So maybe a wrapper or two:
#define hexint_nibble(x) {int y; sscanf(&x,"%1xl",&y); y}
#define hexint_byte(x) {int y; sscanf(x,"%2xl",&y); y}
#define inthex_nibble(x) {char y[2]; sprintf(&y,"%1x",x); y[1]}
#define inthex_byte(x,dest) sprintf(dest,"%02x",x)
Untested, of course.
--
George george@mvista.com
High-res-timers: http://sourceforge.net/projects/high-res-timers/
Real time sched: http://sourceforge.net/projects/rtsched/
prev parent reply other threads:[~2002-02-19 20:32 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-02-19 15:39 [PATCH] hex <-> int conversion routines Jakob Kemi
2002-02-19 15:52 ` Martin Dalecki
2002-02-19 18:49 ` Jakob Kemi
2002-02-19 19:02 ` Bernd Petrovitsch
2002-02-19 20:27 ` H. Peter Anvin
2002-02-23 2:30 ` Ian Molton
2002-02-19 19:04 ` H. Peter Anvin
2002-02-20 10:25 ` Martin Dalecki
2002-02-19 16:51 ` Richard B. Johnson
2002-02-19 18:02 ` Linus Torvalds
2002-02-19 20:29 ` george anzinger [this message]
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=3C72B5C1.2D339F9B@mvista.com \
--to=george@mvista.com \
--cc=jakob.kemi@telia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@transmeta.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.