#!/bin/bash
#########################################################
# 							#
# This is BashStyle-NG  				#
#							#
# Licensed under GNU GENERAL PUBLIC LICENSE v3    	#
#							#
# Copyright 2007 - 2017 Christopher Bratusek		#
#							#
#########################################################

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 "http://www.nanolx.org/"\
			-l "GNU GPL v3" -n "convhex" -s "convert hexadecimal to other numerical equivalents" \
			-v "${BSNG_VERSION}" -y "${BSNG_YEAR}"\
			-o "asc:|convert hexadecimal to ascii equivalent"\
			-o "b32:|convert hexadecimal to base32 equivalent"\
			-o "b64:|convert hexadecimal to base64 equivalent"\
			-o "dec:|convert hexadecimal to decimal equivalent"\
			-o "bin:|convert hexadecimal to binary equivalent"\
			-o "oct:|convert hexadecimal to octal equivalent"\
			-o "all:|convert hexadecimal to other numerical equivalents"
	;;

esac
