Created
December 31, 2023 09:52
-
-
Save TheFlash2k/0c07a7dfab975a1741e28bd2a679017f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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