HP-UX - General

Hexadecimal computation in shell script

 
SOLVED
Go to solution
Rui Vilao
Regular Advisor

Hexadecimal computation in shell script

Hi all,

I am currently working on a shell script that reads hexadecimal values from

A=987BA4
B=0000F2

I have to make computations A*B/2 and present the result in decimal.

Any suggestion how can do this within a shell script?

TIA,

Kind Regards,

Rui.
"We should never stop learning"_________ rui.vilao@rocketmail.com
5 REPLIES 5
Stefan Farrelly
Honored Contributor

Re: Hexadecimal computation in shell script


Heres how to do it;

http://www.dutchworks.nl/htbin/hpsysadmin?h=3&dn=66637&q=hex%20SUMMARY&fh
Im from Palmerston North, New Zealand, but somehow ended up in London...
Paula J Frazer-Campbell
Honored Contributor

Re: Hexadecimal computation in shell script

Hi

Also have a look at :-

od and xd.

Man od, man xd.#



Paula
If you can spell SysAdmin then you is one - anon
Darren Prior
Honored Contributor
Solution

Re: Hexadecimal computation in shell script

bc(1) or dc(1) could be suitable for this usage:

echo "ibase=16; ($A+$B)/2" | bc

echo "16 i $A $B + 2 / p" | dc

regards,

Darren.
Calm down. It's only ones and zeros...
H.Merijn Brand (procura
Honored Contributor

Re: Hexadecimal computation in shell script

man perl
man bc
man dc

# echo "16 i AF 0E + f" | dc
189

A=987BA4
B=0000F2
C=`echo "16 i $A $B * 2 / f" | dc`

Enjoy, Have FUN! H.Merijn
Darren Prior
Honored Contributor

Re: Hexadecimal computation in shell script

ooops - sorry. There's a typo in my examples where I used a + instead of * This also makes the brackets redundant in the bc example.
Calm down. It's only ones and zeros...