Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

How do I print the (numerical) ASCII values of each character in a file?

How can I print the numerical ASCII values of each character in a text file. Like cat, but showing the ASCII values only... (hex or decimal is fine).

Example output for a file containing the word Apple (with a line feed) might look like:
065 112 112 108 101 013 004
by

1 Answer

Bharatgxwzm
hexdump, od, xxd, or $YOUR_FAVORITE_LANGUAGE can all do that.
% echo Apple | hexdump -C
00000000 41 70 70 6c 65 0a |Apple.|
00000006
% echo Apple | perl -ne 'printf "%vd\n", $_'
65.112.112.108.101.10
% echo Apple | clisp <( echo '(print (mapcar #'\''char-code (coerce (read-line standard-input) '\''list)))' )
(65 112 112 108 101)
%

Login / Signup to Answer the Question.