Tags: ascii, characters, characterse, hexadecimal, linux, numbers, prinited, programming, unix

hexadecimal numbers to ASCII characters (in vi)

On Programmer » Unix & Linux

2,501 words with 2 Comments; publish: Wed, 30 Apr 2008 12:17:00 GMT; (20046.88, « »)

I've a some hexadecimal characters. I want them to be prinited as Characters

e.g.

2a 32 57 61 74 63 68 64 6f 67 20 49 6e 74 65 67 72 69 74 79 20 66 61 69 6c

65 64 00 6c 6f 67 00

This i want to convert to characters while editing in vi, so i want to use

some shell command, so that by doing !!<some-shell-command> i get the hex

string replaced with the required character representation.

Thanks!

-Neo

"If you don't program yourself, life will program you!"

All Comments

Leave a comment...

  • 2 Comments
    • On Mon, 10 Jan 2005 at 05:38 GMT, Neo wrote:

      > I've a some hexadecimal characters. I want them to be prinited as Characte

      rs

      > e.g.

      > 2a 32 57 61 74 63 68 64 6f 67 20 49 6e 74 65 67 72 69 74 79 20 66 61 69 6c

      > 65 64 00 6c 6f 67 00

      > This i want to convert to characters while editing in vi, so i want to use

      > some shell command, so that by doing !!<some-shell-command> i get the hex

      > string replaced with the required character representation.

      printf "\x$1\n"

      Chris F.A. Johnson http://cfaj.freeshell.org/shell

      ========================================

      ===========================

      My code (if any) in this post is copyright 2004, Chris F.A. Johnson

      and may be copied under the terms of the GNU General Public License

      #1; Wed, 30 Apr 2008 12:18:00 GMT
    • On Mon, 10 Jan 2005 at 06:28 GMT, Neo wrote:

      > "Chris F.A. Johnson" <cfajohnson.unix-linux.itags.org.gmail.com> wrote in message

      > news:34ej6fF4bh7klU1.unix-linux.itags.org.individual.net...

      > Well, it returns the following error:-

      > printf: missing hexadecimal number in escape

      > what does $1 states here first hex number i.e. 2a or all?

      You can either enter the number as part of the command:

      printf "\x2a\n"

      Or put it into a command. If you want to call it with multiple

      arguments, use this:

      for var

      do

      printf "\x${var}"

      done

      And call it with:

      !!script_name 2a 32 57 61 74 63 68 64 6f 67 20 49 6e 74 65 67 72 69 74 79 2

      0 66 61 69 6c 65 64 00 6c 6f 67 00

      Chris F.A. Johnson http://cfaj.freeshell.org/shell

      ========================================

      ===========================

      My code (if any) in this post is copyright 2004, Chris F.A. Johnson

      and may be copied under the terms of the GNU General Public License

      #2; Wed, 30 Apr 2008 12:19:00 GMT