Created
March 19, 2010 23:02
-
-
Save singpolyma/338295 to your computer and use it in GitHub Desktop.
Implementation of http://tantek.pbworks.com/NewBase60
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Implementation of http://tantek.pbworks.com/NewBase60 | |
# License: http://creativecommons.org/licenses/by-sa/3.0/ | |
n="$1" | |
s='' | |
m='0123456789ABCDEFGHJKLMNPQRSTUVWXYZ_abcdefghijkmnopqrstuvwxyz' | |
if [ -z "$n" ] || [ "$n" -eq "0" ]; then | |
echo 0 | |
exit | |
fi | |
while [ "$n" -gt 0 ]; do | |
d="$(($n % 60))" | |
s="`echo "$m" | cut -c"$(($d + 1))"`$s" | |
n="$(( $(($n - $d)) / 60 ))" | |
done | |
echo "$s" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Implementation of http://tantek.pbworks.com/NewBase60 | |
# License: http://creativecommons.org/licenses/by-sa/3.0/ | |
ord() { | |
echo "$1" | od -tu2 -N1 | head -n1 | awk '{ print $2 }' | |
} | |
s="$1" | |
n=0 | |
j="$((`echo "$s" | wc -c` - 1))" | |
for i in `seq "$j"`; do # iterate from first to last char of $s | |
c="$(ord `echo "$s" | cut -c"$i"`)" # put current ASCII of char into $c | |
if [ $c -ge 48 -a $c -le 57 ]; then | |
c=$(($c - 48)) | |
elif [ $c -ge 65 -a $c -le 72 ]; then | |
c=$(($c - 55)) | |
elif [ $c = 73 -o $c = 108 ]; then # typo capital I, lowercase l to 1 | |
c=1 | |
elif [ $c -ge 74 -a $c -le 78 ]; then | |
c=$(($c - 56)) | |
elif [ $c = 79 ]; then # error correct typo capital O to 0 | |
c=0 | |
elif [ $c -ge 80 -a $c -le 90 ]; then | |
c=$(($c - 57)) | |
elif [ $c = 95 ]; then # underscore | |
c=34 | |
elif [ $c -ge 97 -a $c -le 107 ]; then | |
c=$(($c - 62)) | |
elif [ $c -ge 109 -a $c -le 122 ]; then | |
c=$(($c - 63)) | |
else # treat all other noise as 0 | |
c=0 | |
fi | |
n=$(( $((60 * $n)) + $c )) | |
done | |
echo "$n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nutosxg.sh trips on “08”, “09”, and numbers starting with them because they get treated as octal. Stripping leading zeroes from input (for example by changing
n="$1"
ton="$(echo $1 | sed -r 's/^0+//')"
) prevents it.