Decimal to Hexadecimal conversion

Hi frnds :slight_smile:
I need a small help...
I have a very long file containing 20 digits decimal number which i want to convert into the corresponding 16 digit hexadecimal values.
File looks like....
11908486672755551741
05446378739602232559
04862605079740156652
.
.
.
I tried the script
for i in `cat myfile`
do
echo 'ibase=10;obase=16;$i' | bc
done
but it does not works and gives error "syntax error on line 1, teletype"
please help me out to solve the problem
thnx in advance.

Replace the ' with ". The ' prevents values from getting substituted in place of the variables, which bc does not like.

thanx very much it works...
but one more problem arised the output hexdec which i gets varies in character length some are 15 char while some 16 char. Please help how to make them equi length 16 chars by padding 0 (zero) on left most of 15 char output.
thnx in advance. output looks like...
5566a24546934981
343647852757202
I want...
5566a24546934981
0343647852757202

Use printf. Like this:

for i in `cat test`; do 
   printf "%16s\n" $(echo "ibase=10;obase=16;$i" | bc)
done

This will not add a zero, just a space. To add a zero, pipe the printf through tr ' ' '0'

thnx for reply
but it gives error
syntax error: '(' unexpected
another options available pl.....

You might be using sh. In that case, replace

$(echo "ibase=10;obase=16;$i" | bc)

with

`echo "ibase=10;obase=16;$i" | bc`

It should work. I checked.

:smiley: thnx very much it is working fine....

printf "%x" 123 

gives you hexadecimal number. but wont work for bigger number