Add scripts for base conversion.

This commit is contained in:
2026-02-11 10:51:18 +01:00
parent 093163ecae
commit 0c5d9525af
2 changed files with 43 additions and 0 deletions

27
todec Executable file
View File

@@ -0,0 +1,27 @@
#!/bin/bash
set -euo pipefail
function assert_format() {
if ! [[ "$1" == "0x"* ]]
then
echo "0x$1"
else
echo "$1"
fi
}
if [ $# = 1 ]
then
val=$(assert_format "$1")
printf "%d\n" "$val"
elif [ $# -gt 1 ]
then
for i in "$@"
do
val=$(assert_format "$i")
printf "%X = %d\n" "$val" "$val"
done
else
echo "Usage: $0 <hexadecimal>"
fi

16
tohex Executable file
View File

@@ -0,0 +1,16 @@
#!/bin/bash
set -euo pipefail
if [ $# = 1 ]
then
printf "%x\n" "$1"
elif [ $# -gt 1 ]
then
for i in "$@"
do
printf "%d = 0x%X\n" "$i" "$i"
done
else
echo "Usage: $0 <decimal>"
fi