add dc-based branch
authorgit <redacted>
Thu, 19 Mar 2026 18:21:04 +0000 (14:21 -0400)
committergit <redacted>
Thu, 19 Mar 2026 18:21:04 +0000 (14:21 -0400)
tobin
todec
tohex

diff --git a/tobin b/tobin
index a10a72ddf57e91c77c2386ba691d2499f92d55ed..2223c9ce1bd81084f9f8921b51e366e87f877187 100755 (executable)
--- 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 30affa2bd78f2da95df6c55b0a972cb9dd253477..7c582595a3c424f239a390d7e043cb0a6f90536e 100755 (executable)
--- 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 3eab3b05d8166d23a5ff76d9d710da1da6c18518..1e60b12334363fcd66ad9733598563d9c98d0284 100755 (executable)
--- 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