Tuesday, 11 June 2013

Shell Script to convert number in binary

echo Enter the number
read no
a=$no
s=0
x=1
while(test $a -ne 0)
do
    temp=`expr $a % 2`
    a=`expr $a / 2`
    y=`expr $temp "*" $x`
    s=`expr $s + $y`
    x=`expr $x "*" 10`
done

No comments:

Post a Comment