diff --git a/README.md b/README.md index 8082d58..0735a0e 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,41 @@ # bash-utils -Just a couple bash utilities \ No newline at end of file +Just a couple bash utilities + += a2b - Convert Ascii to Binary = +== Usage == +``` +a2b H e l l o +``` +== Output == +``` +01001000 +01100101 +01101100 +01101100 +01101111 +``` + += a2h - Convert Ascii to Hex = +== Usage == +``` +a2h H e l l o +``` +== Output == +``` +48 +65 +6c +6c +6f +``` + += h2a - Convert Hex to Ascii = +== Usage == +``` +h2a 48 65 6c 6c 6f +``` +== Output == +``` +H e l l o +``` diff --git a/a2b b/a2b new file mode 100755 index 0000000..7c538b9 --- /dev/null +++ b/a2b @@ -0,0 +1,5 @@ +#!/bin/bash + +for c in $@; do + echo $c | xxd -b | cut -d" " -f2 +done diff --git a/a2h b/a2h new file mode 100755 index 0000000..aa5c632 --- /dev/null +++ b/a2h @@ -0,0 +1,5 @@ +#!/bin/bash + +for c in $@; do + echo $c | xxd -p | cut -c1-2 +done diff --git a/h2a b/h2a new file mode 100755 index 0000000..288399d --- /dev/null +++ b/h2a @@ -0,0 +1,10 @@ +#!/bin/bash + +for c in $@; do + if [[ $c != 0x* ]]; then + c="0x$c" + fi + echo $c | xxd -r + echo -n " " +done +printf "\n"