Advertisement
Shailrshah

Base Conversions

Aug 29th, 2014
354
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.62 KB | None | 0 0
  1. #!/bin/bash
  2. echo -n "Enter a numnber: "
  3. read n
  4. echo -n "$n's base is: B->Bin O->Oct D->Dec H->Hex: "
  5. read choice
  6. case $choice in
  7.     B):
  8.         echo 'obase=10; ibase=2; '$n'' | bc
  9.         echo 'obase=16; ibase=2; '$n'' | bc
  10.         echo 'obase=8; ibase=2; '$n'' | bc;;
  11.     D):
  12.         echo 'obase=2; ibase=10; '$n'' | bc
  13.         echo 'obase=16; ibase=10; '$n'' | bc
  14.         echo 'obase=8; ibase=10; '$n'' | bc;;
  15.     O):
  16.         echo 'obase=10; ibase=8; '$n'' | bc
  17.         echo 'obase=2; ibase=8; '$n'' | bc
  18.         echo 'obase=16; ibase=8; '$n'' | bc;;
  19.     H):
  20.         echo 'obase=10; ibase=16; '$n'' | bc
  21.         echo 'obase=2; ibase=16; '$n'' | bc
  22.         echo 'obase=8; ibase=16; '$n'' | bc;;
  23. esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement