Bash: ASCII char to Decimal

#!/bin/bash
# decimal to ASCII char
chr() {
  printf \\$(printf '%o' $1)
}

# ASCII char to decimal number
ord() {
  local c=$1
  [[ $c == '%' ]] && c='%%'
  printf '%d' "'$c"
}

# printalbe ASCII
for i in {33..126}; do
    echo -e "$(chr $i) \t $(ord $(chr $i))\n"
done

Related to: Python: Built-in Function range, ord, chr

Leave a Comment

Your email address will not be published.

5 + ten =