Re: convert hex to decimal?

From: Michael Heiming (michael+USENET_at_www.heiming.de)
Date: 02/08/04

  • Next message: A. Alper ATICI: "Re: convert hex to decimal?"
    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
    

  • Next message: A. Alper ATICI: "Re: convert hex to decimal?"

    Relevant Pages

    • Re: convert hex to decimal?
      ... Michael Heiming writes: ... >> Not when you count time for typing, debugging, etc. ... > Don't know about timing. ...
      (comp.unix.shell)
    • Re: convert hex to decimal?
      ... >> But MANY times slower. ... > Not when you count time for typing, debugging, etc. ... in a script), ...
      (comp.unix.shell)
    • Re: On topic - great software for an MT
      ... professional expander, and, believe me, you really, really, really want ... to simply typing a few characters and hitting a double space or F10. ... been completely blown away by the results, a single script that lets ...
      (sci.med.transcription)
    • Re: Help!! crazy awk unix shlle script
      ... Execute teh program by typing: ... main.ksh data HAIR AGE EYES ... colon-separated field names, ... write a script, named extract_columns, that prints out the values ...
      (comp.lang.awk)
    • lesspipe [Was: Re: OpenSSH]
      ... of work, which was to revise my /usr/local/bin/lesspipe script, ... Then 'less' can display squished files just by typing, e.g., ... It obviates the need for 'zless', usually supplied by gzip source, and ...
      (comp.unix.sco.misc)