Skip to content

Instantly share code, notes, and snippets.

@TheFlash2k
Created December 31, 2023 09:52
Show Gist options
  • Save TheFlash2k/0c07a7dfab975a1741e28bd2a679017f to your computer and use it in GitHub Desktop.
Save TheFlash2k/0c07a7dfab975a1741e28bd2a679017f to your computer and use it in GitHub Desktop.
#!/bin/bash
if [[ $# != 1 ]]; then
echo "Usage: $0 <string>"
exit 1
fi
function endian() {
if [[ -z $1 ]]; then echo "No input supplied."; exit 1; fi
v=$1
i=${#v}
while [ $i -gt 0 ]; do
i=$[$i-2]
echo -n ${v:$i:2}
done
}
_hex=$(echo -n "$1" | od -A n -t x1 | tr -d " ")
_little=$(endian $_hex)
echo "String: $1"
echo "Base: $_hex"
echo "Little endian: $_little"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment