#!/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 $((2#$2)))" ;;
	b32 | base32)	echo "obase=32 ; ibase=2 ; $2 " | bc ;;
	b64 | base64)	echo "obase=64 ; ibase=2 ; $2" | bc ;;
	dec | decimal)	echo $((2#$2)) ;;
	hex | hexadecimal)	echo "obase=16 ; ibase=2 ; $2" | bc ;;
	oct | octal)	echo "obase=8 ; ibase=2 ; $2" | bc ;;
	all )
		echo "binary $2 = octal		$(convbin oct "${2}")
binary $2 = decimal		$(convbin dec "${2}")
binary $2 = hexadecimal	$(convbin hex "${2}")
binary $2 = base32		$(convbin b32 "${2}")
binary $2 = base64		$(convbin b64 "${2}")
binary $2 = ascii		$(convbin asc "${2}")"
	;;

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