Skip to content

Instantly share code, notes, and snippets.

@jmmitchell
Last active October 18, 2024 13:36
Show Gist options
  • 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