I need to convert a number from hexadecimal form to decimal form using shell script
for example :
convert()
{
...
echo x=$decimal
}
result :
convert "0x148FA1"
x=1347489
How to do it?
You can convert in many different ways, all within bash, and relatively easy.
To convert a number from hexadecimal to decimal:
$ echo $((0x15a))
346
$ printf '%d\n' 0x15a
346
$ perl -e 'printf ("%d\n", 0x15a)'
346
$ echo 'ibase=16;obase=A;15A' | bc
346
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With