SHARE
TWEET

decimal2base12.sh

h8rt3rmin8r Jan 2nd, 2019 (edited) 95 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #! /bin/bash
  2. # BASE 12 - DECIMAL INPUT CONVERSION SCRIPT
  3.  
  4. function decimal2base12() {
  5.     number=$(echo "$1" | tr -s '[:lower:]' '[:upper:]' )
  6.  
  7.     # "obase" = The base to convert into
  8.     #
  9.     # "ibase" = The base you are coming from as expressed in the base you
  10.     #           want to convert into
  11.  
  12.     result=$(echo "obase=$obase;ibase=$ibase;$number" | bc)
  13.  
  14.     if [ ! "$?" == "0" ]; then echo ""; exit 1; fi
  15.     echo "$result"
  16. }
  17.  
  18. obase=12
  19. ibase=A
  20. decimal2base12 "$1"
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top