Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

convert Hexa number to an Octal 2

Status
Not open for further replies.

MoshiachNow

IS-IT--Management
Feb 6, 2002
1,851
IL
Hi,

Is there a one command to convert Hexa number to an Octal one ?

"Long live king Moshiach !"
 
Thanks,

I actualy need to convert the PVID from hexa to octal.
Like :0058dd2a7f9e02d8

bc does not seem to do it right.

"Long live king Moshiach !"
 
you have to convert is step by step...like in example

> 00012a3e42bc908f3 -> 00 12 a3 e4 2b c9 08 f3
> Octal version -> 000 022 243 344 053 311 010 363
 
$ for i in 00 12 A3 E4 2B C9 08 F3;do echo $i: `echo "ibase=16; obase=8; $i" | bc`;done
00: 0
12: 22
A3: 243
E4: 344
2B: 53
C9: 311
08: 10
F3: 363
 
Too much time on my hands, I guess:

Code:
function pvid_h2o {
typeset -u NUM=$1
RSLT=""
while [ ${#NUM} -gt 0 ]
do
   TMP=${NUM#[0-9,A-F]?}
   VAL=${NUM%%${TMP}}
   RSLT=${RSLT}$(printf "%0.3d" `echo "ibase=16;obase=8;${VAL}" | bc`)" "
   NUM=$TMP
done
echo $RSLT
}

Season to taste. I suppose it could be more generally named "bytewise_hex2octal".

Rod Knowlton
IBM Certified Advanced Technical Expert pSeries and AIX 5L

 
Thanks, Ken.

I can never resist questions of the form "can I do X in programming language Y?", if I've worked in Y. :)



Rod Knowlton
IBM Certified Advanced Technical Expert pSeries and AIX 5L

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top