-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathb2d
More file actions
46 lines (40 loc) · 1.2 KB
/
b2d
File metadata and controls
46 lines (40 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/sh
#
# base-convert - Copyright (C) 2002 Murray Nesbitt (websrc@nesbitt.ca)
#
# This program is protected and licensed under the following terms and
# conditions: 1) it may not be redistributed in binary form without the
# explicit permission of the author; 2) when redistributed in source
# form, in whole or in part, this complete copyright statement must
# remain intact.
if [ "$1" = "" ]
then
read arg
else
arg=$1
fi
if [ "$arg" = "" ] || [ "$2" != "" ]
then
echo "Usage: $0 num"
echo "Example: b2d 10001 converts binary => decimal (17)"
echo " h2o FF converts hexadecimal => octal (377)"
echo " d2h 128 converts decimal => hexadecimal (80)"
exit 1;
fi
arg=`echo $arg | tr a-f- A-F_`
case $0 in
*b2d) prog="10o2i${arg}p" ;;
*b2h) prog="16o2i${arg}p" ;;
*b2o) prog="8o2i${arg}p" ;;
*d2b) prog="2o10i${arg}p" ;;
*d2h) prog="16o10i${arg}p" ;;
*d2o) prog="8o10i${arg}p" ;;
*h2b) prog="2o16i${arg}p" ;;
*h2d) prog="10o16i${arg}p" ;;
*h2o) prog="8o16i${arg}p" ;;
*o2b) prog="2o8i${arg}p" ;;
*o2d) prog="10o8i${arg}p" ;;
*o2h) prog="16o8i${arg}p" ;;
*) echo "$0: who the hell am I?"
esac
echo $prog | dc