awk, how to convert hex to decimal
D'Arcy J.M. Cain
darcy at druid.uucp
Fri Feb 8 05:07:43 AEST 1991
In article <23000 at well.sf.ca.us> gregs at 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 at druid) |
D'Arcy Cain Consulting | There's no government
West Hill, Ontario, Canada | like no government!
+1 416 281 6094 |
More information about the Comp.unix.shell
mailing list