Last active
October 18, 2024 13:36
-
-
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
This file contains 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 | |
# 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