~johanvandegriff/unix-shell-programming-revised-edition-programs

unix-shell-programming-revised-edition-programs/bin2dec.sh -rw-r--r-- 294 bytes
fc214385Johan Vandegriff added other old scripts, some newer ones too 1 year, 8 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#!/bin/sh
echo "Type in a binary number."
read binary
binary=`echo "$binary" | rev`
decimal=0
i=0
add=1
while [ "$i" -lt `echo "$binary" | wc -l` ]
do
  i=`expr "$i" + 1`
  test echo "$binary" | cut "-c$i-$i" && decimal=`expr "$decimal" + "$add"`
  add=`expr "$add" "*" 2`
done
echo "$decimal"