Advertisement
Guest User

Untitled

a guest
Mar 24th, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. # copy to your bash_profile or somewhere you write aliases,
  2. # then you can convert a number to different base by cbase
  3. # エイリアスを設定しているあたりにでも以下のコードをコピペすると基数変換がcbaseコマンドで簡単できるようになります
  4. function cbase() {
  5. function echo_usage() {
  6. cat << USAGE
  7. usage: cbase [-i num] [-o num] num
  8. -i num
  9. Set a number of base you want to convert FROM.
  10. Default is 10.
  11. -o num
  12. Set a number of base you want to convert TO.
  13. Default is 10.
  14. USAGE
  15. }
  16.  
  17. local OPTIND OPT OPTERR input output
  18. while getopts "i:o:" OPT; do
  19. case "$OPT" in
  20. i) input="$OPTARG" ;;
  21. o) output="$OPTARG" ;;
  22. esac
  23. done
  24. shift $(($OPTIND - 1))
  25.  
  26. [ -z "$input" -a -z "$output" ] && echo_usage
  27.  
  28. [ -z "$input" ] && input=10
  29. [ -z "$output" ] && output=10
  30. echo "obase=$output; ibase=$input; $1" | bc
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement