This is a small script to convert hex number to decimal numbers. Here we can use different machination to do this. One is to use inbuilt (()) braces to do this. Hexadecimal numbers have base as 16. So if I consider hex value of 13, it will be equal to 1*16+3=19 decimal value.

Below we will see number of ways to do this conversion using .

Method1: Use (()) brace expatiation. 

#!/bin/bash
read -p “Please enter HEX number: ” HEX1
echo “The decimal value of $HEX1 is $((16#$HEX1))”

Save above file as hex2dec.sh

Change permissions to this script now and execute as follows

chmod +x hex2dec.sh

./hex2dec.sh

Method2: Using bc command

#!/bin/bash
read -p “Please enter HEX number: ” HEX1

echo “ibase=16; $HEX1” | bc

Save above file as hex2dec.sh

Change permissions to this script now and execute as follows

chmod +x hex2dec.sh

./hex2dec.sh


The following two tabs change content below.
Mr Surendra Anne is from Vijayawada, Andhra Pradesh, India. He is a Linux/Open source supporter who believes in Hard work, A down to earth person, Likes to share knowledge with others, Loves dogs, Likes photography. He works as Devops Engineer with Taggle systems, an IOT automatic water metering company, Sydney . You can contact him at surendra (@) linuxnix dot com.