Can someone help me to convert a hexadecimal number to decimal number in a shell script?
E.g., I want to convert the hexadecimal number bfca3000 to decimal using a shell script. I basically want the difference of two hexadecimal numbers.
My code is:
var3=`echo "ibase=16; $var1" | bc`
var4=`echo "ibase=16; $var2" | bc`
var5=$(($var4-$var3)) # [Line 48]
When executing, I get this error:
Line 48: -: syntax error: operand expected (error token is "-")
To convert from hex to decimal, there are many ways to do it in the shell or with an external program:
With bash:
with bc:
with perl:
with printf :
with python:
with ruby:
with node.js:
with rhino:
with groovy: