I\'m now doing it this way:
[root@~]# echo Aa|hexdump -v 0000000 6141 000a 0000003 [root@~]# echo -e \"\\x41\\x41\\x41\\x41\" A
I use:
> echo Aa | tr -d '\n' | xxd -p 4161 > echo 414161 | tr -d '\n' | xxd -r -p AAa
The tr -d '\n' will trim any possible newlines in your input
tr -d '\n'