Convert Ascii to Its Decimal Value

There is online tool that can convert text to ASCII such as this one. Would it be possible to do the same thing in Ubuntu/Linux?

E.g.

Input data: abc

Output as ASCII: 097 098 099
3

3 Answers

Take a look at the old standby, od. Your ASCII to decimal would be:

echo -n abc | od -td1

See the man page for od, or "octal dump",

man od  

For the many options in converting input to other forms -- hex, decimal, ASCII, char, etc.

2

You want to convert from ASCII symbol to its decimal value.

The complete table is on man ascii (or just ascii).

ASCII to decimal: "a" → "97"

printf "%d\n" \'a

Decimal to ASCII: "97" → "a"

printf '%b' $(printf '\\%03o' "97")
2

Another way to do this, with Perl's unpack:

$ echo abc | perl -lne 'print join " ", unpack("C*")'
97 98 99

More verbosely using split and ord,

$ echo abc | perl -lne 'print join " ", map { ord $_ } split //'
97 98 99

Reference: Converting Between ASCII Characters and Values

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Sarah Jenkins

Sarah Jenkins

Senior Technology Editor & AI Specialist

Sarah Jenkins is a veteran tech journalist with over 12 years of experience covering artificial intelligence, mobile innovations, and digital ethics. Her insights have appeared in leading technology publications worldwide.

Share this article
Twitter Facebook Pinterest