From: git Date: Thu, 19 Mar 2026 18:21:04 +0000 (-0400) Subject: add dc-based branch X-Git-Url: https://git.datadissipation.net/?a=commitdiff_plain;h=afc152e65943fb50d71b8ba53cdd91dd04272256;p=baseconv.git add dc-based branch --- diff --git a/tobin b/tobin index a10a72d..2223c9c 100755 --- a/tobin +++ b/tobin @@ -7,14 +7,14 @@ conv() { printf "Decimal %s → Binary: " "$1" fi printf "%s" "$p" - printf "obase=2; %s" "$1" | bc + printf "%s 2o p" "$1" | dc elif printf "%s" "$1" | grep -qE '^([0-9A-Fa-f]+|0x[0-9A-Fa-f]+)$'; then if [ "$m" -eq 0 ]; then printf "Hex %s → Binary: " "$1" fi printf "%s" "$p" - printf "ibase=16; obase=2; %s" "$(printf "%s" "$1" | sed 'y/abcdef/ABCDEF/; s/^0x//')" | bc + printf "16i %s 2o p" "$(printf "%s" "$1" | sed 'y/abcdef/ABCDEF/; s/^0x//')" | dc else printf "Error: '%s' is not a valid decimal or hexadecimal number\n" "$1" >&2 diff --git a/todec b/todec index 30affa2..7c58259 100755 --- a/todec +++ b/todec @@ -7,14 +7,14 @@ conv() { printf "Binary %s → Decimal: " "$1" fi t=$(printf "%s" "$1" | sed 's/^0b//') - printf "ibase=2; %s / %s" "$t" "$k" | bc | tr -d '\n' && printf "%s\n" "$p" + printf "2i %s %s / p" "$t" "$k" | dc | tr -d '\n' && printf "%s\n" "$p" elif printf "%s" "$1" | grep -qE '^([0-9A-Fa-f]+|0x[0-9A-Fa-f]+)$'; then if [ "$m" -eq 0 ]; then printf "Hex %s → Decimal: " "$1" fi - t=$(printf "%s" "$1" | sed 's/^0x//') - printf "ibase=16; %s / %X" "$(printf "%s" "$t" | sed 'y/abcdef/ABCDEF/')" "0b$k" | bc | tr -d '\n' && printf "%s\n" "$p" + t=$(printf "%s" "$1" | sed 'y/abcdef/ABCDEF/; s/^0x//') + printf "16i %s %s / p" "$t" "$k" | dc | tr -d '\n' && printf "%s\n" "$p" else printf "Error: '%s' is not a valid decimal or hexadecimal number\n" "$1" >&2 diff --git a/tohex b/tohex index 3eab3b0..1e60b12 100755 --- a/tohex +++ b/tohex @@ -6,13 +6,15 @@ conv() { if [ "$m" -eq 0 ]; then printf "Decimal %s → Hex: " "$1" fi - printf "%s%X\n" "$p" "$1" + printf "%s" "$p" + printf "%s 16o p" "$1" | dc elif printf "%s" "$1" | grep -qE '^0b[0-1]+$'; then if [ "$m" -eq 0 ]; then printf "Binary %s → Hex: " "$1" fi - printf "%s%X\n" "$p" "$1" + printf "%s" "$p" + printf "2i %s 10000o p" "$(printf "%s" "$1" | sed 's/^0b//')" | dc else printf "Error: '%s' is not a valid binary or decimal number\n" "$1" >&2