Ascii/Hex convert in bash Ascii/Hex convert in bash bash bash

Ascii/Hex convert in bash


The reason is because hexdump by default prints out 16-bit integers, not bytes. If your system has them, hd (or hexdump -C) or xxd will provide less surprising outputs - if not, od -t x1 is a POSIX-standard way to get byte-by-byte hex output. You can use od -t x1c to show both the byte hex values and the corresponding letters.

If you have xxd (which ships with vim), you can use xxd -r to convert back from hex (from the same format xxd produces). If you just have plain hex (just the '4161', which is produced by xxd -p) you can use xxd -r -p to convert back.


For the first part, try

echo Aa | od -t x1

It prints byte-by-byte

$ echo Aa | od -t x10000000 41 61 0a0000003

The 0a is the implicit newline that echo produces.

Use echo -n or printf instead.

$ printf Aa | od -t x10000000 41 610000002


$> printf "%x%x\n" "'A" "'a"4161