coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Hex to ASCII conversion?


From: Bernhard Voelker
Subject: Re: Hex to ASCII conversion?
Date: Thu, 25 Dec 2014 23:09:48 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0

On 12/25/2014 09:04 PM, Bob Proulx wrote:
> 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

> [...]

> 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?

I only know of the double-folded printf way via octal:

  $ env printf $(env printf '\\%03o' 0x48 0x61 0x70 0x70 0x79)
  Happy

(The additional 'env' is to force the use of coreutils printf rather
than that of the shell.)

This is e.g. used in tests/dd/ascii.sh to get all bytes from 0..255
as  ASCII characters.

Have a nice day,
Berny




reply via email to

[Prev in Thread] Current Thread [Next in Thread]