Skip to content

Instantly share code, notes, and snippets.

@jmmitchell
Last active December 1, 2021 18:07
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmmitchell/c82b03e3fc2dc0dcad6c95224e42c453 to your computer and use it in GitHub Desktop.
Save jmmitchell/c82b03e3fc2dc0dcad6c95224e42c453 to your computer and use it in GitHub Desktop.
converting from decimal value to the ascii character and from the ascii character to the ordinal number in bash
#!/bin/bash
# chr() - converts decimal value to its ASCII character representation
# ord() - converts ASCII character to its decimal value
chr() {
printf \\$(printf '%03o' $1)
}
ord() {
printf '%d' "'$1"
}
ord A
echo
chr 65
echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment