Below we will see number of ways to do this conversion using .
Method1: Use (()) brace expatiation. Let me explain below code
#!/bin/bash
read -p “Please enter a BINARY number: ” BIN1
echo “The decimal value of $HEX1 is $((2#$BIN1))”
Save above file as bin2dec.sh
Change permissions to this script now and execute as follows
chmod +x bin2dec.sh
Executing shell script
./bin2dec.sh
Method2: Using bc command
#!/bin/bash
read -p “Please enter BIN number: ” BIN1
echo “ibase=8; $BIN1” | bc
Save above file as bin2dec.sh
Change permissions to this script now and execute as follows
chmod +x bin2dec.sh
Executing shell script./bin2dec.sh
Latest posts by Surendra Anne (see all)
- Docker: How to copy files to/from docker container - June 30, 2020
- Anisble: ERROR! unexpected parameter type in action:
Fix - June 29, 2020 - FREE: JOIN OUR DEVOPS TELEGRAM GROUPS - August 2, 2019
- Review: Whizlabs Practice Tests for AWS Certified Solutions Architect Professional (CSAP) - August 27, 2018
- How to use ohai/chef-shell to get node attributes - July 19, 2018