#!/bin/bash## bconv## converts integers from one base to another# defaults to base 10 for input and base 10 for output# bases in the range of 2 to 16 onlyi_flag='10'o_flag='10'
print_usage(){printf"Usage: bconv [-i input_base] [-o output_base] number\n"}while getopts':i:o:h' flag;do
case"${flag}"in
i)i_flag="$OPTARG";;
o)o_flag="$OPTARG";;
h) print_usage
exit 0 ;;esacdone
shift$((OPTIND-1))if["$1"==""];then
print_usage
exit 1
fi# clean the input - dc can only accept upper case letters for numbersinput=$(echo$1| tr'[:lower:]''[:upper:]')# use dc(1) for the calculation
dc -e"$o_flag o $i_flag i $input p"
Been reading/writing about dc(1) and thought I'd try and build something with it... it's probably easier just to remember
dc -e'2 o 16 i DEADBEEF p'
but it was fun
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
this
Been reading/writing about dc(1) and thought I'd try and build something with it... it's probably easier just to remember
but it was fun