OS Mini project
Operating System Mini Project
#This is a program that converts any number from #one format to another according to user input bin2Dec() { n=0 dec=0 read -p "Enter Binary Number : " n dec=`expr "ibase=2; $n" | bc` echo "decimal equivalent is $dec " } dec2Bin() { read -p "Enter the Decimal number " n val=0 power=1 while [ $n -ne 0 ] do r=`expr $n % 2` val=`expr $r \* $power + $val` power=`expr $power \* 10` n=`expr $n \/ 2` done echo "Binary equivalent=$val" } dec2Hexd() { n=0 hex=0 read -p "Enter Number in decimal format : " n hex=`expr "obase=16; $n" | bc` echo "$n is equivalent \"$hex\" in Hexadecimal" } dec2Oct() { n=0 oct=0 read -p "Enter Number in Decimal format : " n oct=`expr "obase=8; $n" | bc` echo "Octal number is $oct" } oct2Dec() { n=0 dec=0 read -p "Enter number in Octal format : " n dec=`expr "ibase=8; $n" | bc` echo "Decimal conversion is $dec" } hex2Dec() { n=0 dec=0 read -p "Ener number is Hexadecimal format : " n dec=`expr "ibase=16; $n" | bc` echo "Decmial equivalent is $dec" } bin2Oct() { n=0 oct=0 read -p "Enter number in Binary format : " n oct=`expr "ibase=2;obase=8; $n" | bc` echo "Octal equivalent is $oct" } dec2any() { n=0 any=0 base=0 read -p "Enter number in decimal format : " n read -p "Enter value of base : " base any=`expr "obase=$base; $n" | bc` echo "$n in base $base is $any" } i=0 while [ $i != 9 ] do echo "Number Converter 1. Binary to decimal 2. Decimal to binary 3. Decimal to Hexadecimal 4. Decimal to Octal 5. Octal to decimal number 6. Hexadecimal to decimal number 7. Binary to octal converter 8. Decimal to any base Number 9. Exit Choose your option and enter corresponding value" read i case "$i" in 1) bin2Dec ;; 2) dec2Bin ;; 3) dec2Hexd ;; 4) dec2Oct ;; 5) oct2Dec ;; 6) hex2Dec ;; 7) bin2Oct ;; 8)dec2any ;; esac done
Output
Comments