#!/bin/bash
#########################################################
#                                                       #
# This is BashStyle-NG                                  #
#                                                       #
# Licensed under GNU GENERAL PUBLIC LICENSE v3          #
#                                                       #
# Copyright Christopher Roy Bratušek                    #
#                                                       #
#########################################################

. gettext.sh
export TEXTDOMAIN="bashstyle-rc"

case ${1} in
    asc | ascii)    echo -e "\0$(printf %o $((16#$2)))" ;;
    b32 | base32)   echo "obase=32 ; ibase=16 ; $2" | bc ;;
    b64 | base64)   echo "obase=64 ; ibase=16 ; $2" | bc ;;
    bin | binary)   echo "obase=2 ; ibase=16 ; $2" | bc ;;
    dec | decimal)  echo $((16#$2)) ;;
    oct | octal)    echo "obase=8 ; ibase=16 ; $2" | bc ;;
    all)
        echo "hexadecimal $2 = binary   $(convhex bin "${2}")
hexadecimal $2 = octal      $(convhex oct "${2}")
hexadecimal $2 = decimal    $(convhex dec "${2}")
hexadecimal $2 = base32 $(convhex b32 "${2}")
hexadecimal $2 = base64 $(convhex b64 "${2}")
hexadecimal $2 = ascii      $(convhex asc "${2}")"
    ;;

    *)
        bashstyle-help -a "Christopher Roy Bratusek" -e "nano@jpberlin.de" -h "https://www.nanolx.org/"\
            -l "GNU GPL v3" -n "convhex" -s "$(eval_gettext "convert hexadecimal to other numerical equivalents")"\
            -v "${BSNG_VERSION}" -y "${BSNG_YEAR}"\
            -o "$(eval_gettext "asc:|convert hexadecimal to ascii equivalent")"\
            -o "$(eval_gettext "b32:|convert hexadecimal to base32 equivalent")"\
            -o "$(eval_gettext "b64:|convert hexadecimal to base64 equivalent")"\
            -o "$(eval_gettext "dec:|convert hexadecimal to decimal equivalent")"\
            -o "$(eval_gettext "bin:|convert hexadecimal to binary equivalent")"\
            -o "$(eval_gettext "oct:|convert hexadecimal to octal equivalent")"\
            -o "$(eval_gettext "all:|convert hexadecimal to other numerical equivalents")"
    ;;
esac
