#!/bin/bash # bc -q <<<"obase=$1;$2" set -eu if [[ $# -eq 0 ]] || [[ $# -gt 2 ]] then cat >&2 <<-HERE usage: $0 radix decimal HERE exit fi declare -i radix=$1 declare -i decimal=$2 [[ radix -gt 0 ]] || exit 1 if [[ $decimal -lt 0 ]] then printf -- - decimal=-$decimal fi if [[ $radix -eq 12 ]] then digits=({0..9} ↊ ↋) else digits=({0..9} {a..z}) fi number='' while [[ $decimal -gt 0 ]] do digit=$((decimal%radix)) number=${digits[$digit]}$number # decimal=$((decimal-(digit*radix))) decimal=$((decimal/radix)) done echo "$number"