[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Hex to ASCII conversion?
From: |
Bob Proulx |
Subject: |
Hex to ASCII conversion? |
Date: |
Thu, 25 Dec 2014 13:04:30 -0700 |
User-agent: |
Mutt/1.5.23 (2014-03-12) |
I have a string of hex encoded us-ascii characters. The hex sequence
48 61 70 70 79 is obviously "Happy". Is there an easy way to convert
them to ascii using printf? It seems like there should be.
$ printf "%c\n" 0x48 0x61 0x70 0x70 0x79
0
0
0
0
0
Nope. It doesn't operate like C does.
$ printf "%c\n" h e l l o
h
e
l
l
o
Although of course I can use printf to convert from hex to decimal it
looks like I can't use it for converting from hex to ascii.
Of course the perl printf works like the C printf.
$ perl -le 'printf("%c\n",0x48);'
H
So this works.
$ for c in 48 61 70 70 79; do perl -le 'printf("%c\n",0x'$c');'; done; echo
H
a
p
p
y
Is there any way to use the shell printf like the C printf and do this
conversion in the coreutils printf? Or perhaps another way?
Bob
- Hex to ASCII conversion?,
Bob Proulx <=