Converting the list of hexadecimal numbers

 
#! bin/bash
# hexa number to decimals


echo "Type a hex number"
read hexNum

echo -n "The decimal value of $hexNum="
echo "obase=10; ibase=16; $hexNum" | bc

: '
another approaches:
#!/bin/bash
echo -n "The decimal value of $@="
echo "ibase=16; $@"|bc

#!/bin/bash
echo "Type a hex number"
read hexNum
printf "The decimal value of $hexNum=%d\n" $((16#$hexNum))

#!/bin/bash
echo "Type a hex number"
read hexNum
echo $(( 16#$hexNum ))
'




[prabhucloudxlab@cxln4 ~]$ sh hello.sh
Type a hex number
FF
The decimal value of FF=255

[prabhucloudxlab@cxln4 ~]$ sh hello.sh
Type a hex number
FFFF
The decimal value of FFFF=65535



=========================================================================

#!/bin/bash
#Converting the list of hexadecimal numbers

: '
[prabhucloudxlab@cxln4 ~]$ cat>hexList.txt
AB05
FF
ABCD
ACCD
BED
'


while read number
do
echo -n "The decimal value of $number(Hex)="
echo "obase=10; ibase=16; $number" | bc
done < hexList.txt


[prabhucloudxlab@cxln4 ~]$ sh hello.sh
The decimal value of AB05(Hex)=43781
The decimal value of FF(Hex)=255
The decimal value of ABCD(Hex)=43981
The decimal value of ACCD(Hex)=44237
The decimal value of BED(Hex)=3053