hex data conversion

Dear friends,

I have hexadecimal data like this.

now i want to read each letter and convert to decimal format.

for example.:

from the below data first i have to read hex data 0 and convert to 4 bit decimal value ie 0000.

similarly second letter 8 decimal value is 1000.

like this.

each decimal value i have to store in one variable.

data:

085F40 00401C 09581B 0112D4 034AB6 0581D9 04AF17 068AB5 00D962 0C9140 000000 000000 000000

is there any unix function directly convert this Hex data to decimal data.

please help me.

thanks in advance.

Do you mean binary? Hex 8 is 1000 in binary not decimal. Anyway, use bc for base conversions, e.g...

$ echo 'ibase=16; obase=2; 8'|bc
1000

yes thank u ygor.

your script is working fine.

but the problem is if i give hex numbers from 0 to 7 the output is not 4 bit binary.

for example:

if i give
echo 'ibase=16; obase=2; 2' | bc
10

but actually i want 4 bit binary number .

like this.

if i give 2 then it should be 0010 not 01

how it is possible.

please help.

regards
rajan

Perhaps look at the man pages for printf.

suppose you are reading the binary value in a variable s odo it like this

Gaurav

Note that typeset -Z is only available in ksh.

is typeset -z will work in csh or not

if it works please give me syntax.