HP-UX - General

# Hexadecimal computation in shell script

SOLVED
Go to solution

## 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
Honored Contributor

## Re: Hexadecimal computation in shell script

Heres how to do it;

Im from Palmerston North, New Zealand, but somehow ended up in London...
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
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...
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
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...