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

case ${1} in

	b32 | base32)	echo "obase=32 ; $(convasc dec "${2}")" | bc ;;
	b64 | base64)	echo "obase=64 ; $(convasc dec "${2}")" | bc ;;
	bin | binary)	echo "obase=2 ; $(convasc dec "${2}")" | bc ;;
	dec | decimal)	printf '%d\n' "'$2'" ;;
	hex | hexadecimal)	echo "obase=16 ; $(convasc dec "${2}")" | bc ;;
	oct | octal)	echo "obase=8 ; $(convasc dec "${2}")" | bc ;;
	all )
		echo "ascii $2 = binary	$(convasc bin "${2}")
ascii $2 = octal		$(convasc oct "${2}")
ascii $2 = decimal	$(convasc dec "${2}")
ascii $2 = hexadecimal	$(convasc hex "${2}")
ascii $2 = base32	$(convasc b32 "${2}")
ascii $2 = base64	$(convasc b64 "${2}")"
	;;

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

esac
