Skip to content

Instantly share code, notes, and snippets.

@deliciouskek
Last active March 16, 2016 00:54
Show Gist options
  • Save deliciouskek/f08ab03f447d2c359fb6 to your computer and use it in GitHub Desktop.
Save deliciouskek/f08ab03f447d2c359fb6 to your computer and use it in GitHub Desktop.
hexcount.sh
#!/bin/sh
#
# hexcount - POSIX Shell script to count from $1 to $2 in hex
# modified from user "Jens" answer found at http://stackoverflow.com/questions/5517500/simple-shell-script-for-generating-hex-numbers-of-a-certain-range
# maximum digits of $1 and $2.
# Example: hexcount.sh 0000 FFFF
FROM=$1 TO=$2
if test ${#FROM} -gt ${#TO}; then
FORMAT="0x%0${#FROM}X\n"
else
FORMAT="0x%0${#TO}X\n"
fi
FROM=$(printf '%d' 0x$FROM) TO=$(printf '%d' 0x$TO)
while test $FROM -le $TO; do
printf $FORMAT $FROM
FROM=$((FROM+1))
done
printf '\n'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment