Re: convert hex to decimal?
From: Michael Heiming (michael+USENET_at_www.heiming.de)
Date: 02/08/04
- Previous message: Chris F.A. Johnson: "Re: convert hex to decimal?"
- In reply to: Chris F.A. Johnson: "Re: convert hex to decimal?"
- Next in thread: Chris F.A. Johnson: "Re: convert hex to decimal?"
- Reply: Chris F.A. Johnson: "Re: convert hex to decimal?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 8 Feb 2004 00:57:06 +0100
Chris F.A. Johnson <c.fa.johnson@rogers.com> wrote:
> On Sat, 07 Feb 2004 at 21:23 GMT, William Park wrote:
> > Chris F.A. Johnson <c.fa.johnson@rogers.com> wrote:
> >> On Sat, 07 Feb 2004 at 20:45 GMT, joe@invalid.address wrote:
> >> > William Park <opengeometry@yahoo.ca> writes:
> >> >> How about
> >> >> printf "%d.%d.%d.%d\n" `echo ffffff80 | sed 's/../ 0x&/g'`
> >> >
> >> > That's better than mine alright.
> >>
> >> But MANY times slower.
> >
> > Not when you count time for typing, debugging, etc.
> If it's a one-time execution, you may be right, but if it's in a
> script that is run many times (or if it's executed several times
> in a script), then it is definitely slower. (The difference will
> be much more pronounced in bash than in ksh.)
[..]
> The biggest difference is probably the time taken to think of the
> method, and that will vary from person to person. I'd come up with
Ack, came up with using bc quite fast.
> a solution like Joe's much faster than one using sed. FWIW, here's
> mine:
> hex=ffffff80
> h1=${hex%????}
> h2=${hex#????}
> printf "%d.%d.%d.%d\n" 0x${h1%??} 0x${h1#??} 0x${h2%??} 0x${h2#??}
Timed your solution, William's and mine:
After a few hundred runs it finishes:
real 0m0.007s (CFAJ)
real 0m0.012s (William P.)
real 0m0.012s (Michael H.)
>From a programmer view, yours should be the cleanest/fastest. But
from my point, the fastest typing is what counts.
;)
Greetings
-- Michael Heiming - RHCE Remove +SIGNS and www. if you expect an answer, sorry for inconvenience, but I get tons of SPAM
- Previous message: Chris F.A. Johnson: "Re: convert hex to decimal?"
- In reply to: Chris F.A. Johnson: "Re: convert hex to decimal?"
- Next in thread: Chris F.A. Johnson: "Re: convert hex to decimal?"
- Reply: Chris F.A. Johnson: "Re: convert hex to decimal?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|