Newsgroups: comp.unix.shell Path: utzoo!telly!problem!druid!darcy From: darcy@druid.uucp (D'Arcy J.M. Cain) Subject: Re: awk, how to convert hex to decimal Message-ID: <1991Feb7.180743.8596@druid.uucp> Summary: A partial answer and a question Organization: D'Arcy Cain Consulting, West Hill, Ontario References: <23000@well.sf.ca.us> Distribution: na Date: Thu, 7 Feb 91 18:07:43 GMT In article <23000@well.sf.ca.us> gregs@well.sf.ca.us (Greg Strockbine) writes: >How do I convert a hex number (or is it string) into decimal? The following command will convert a hex number such as 93 (stored as HEXNUM) into decimal: DECNUM=`echo "16 i $HEXNUM p" | dc` However on my system (Esix Rel D SysV3.2) at least it won't work on the output from hd(1) since it barfs on lower case letters. Is this the normal way for dc to work? I guess the following line will be a general purpose converter but I'm sure there must be a better way. HEXNUM=`echo $HEXNUM | tr [a-z] [A-Z]` DECNUM=`echo "16 i $HEXNUM p" | dc` -- D'Arcy J.M. Cain (darcy@druid) | D'Arcy Cain Consulting | There's no government West Hill, Ontario, Canada | like no government! +1 416 281 6094 |