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

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like