From: "Stephane Tsacas"
<stephane.tsacas(a)gmail.com>
ahhhhh okay :)
You mean if you have 23 as input (2 digits/ascii code of 2 and 3) the
output should be the binary value 0x23 in one byte. Correct ?
So input is ascii and output is a binary file, not ascii.
Hi Stephane
Now you got it.
Dwight
awk --non-decimal-data 'BEGIN {RS=" "} {x="0x"$0;
printf("%c", 0+x);}' |
od -t x1
0 1 2 3 4 5 6 7 8 9 A B C D E F 10 11 1F 20 FA FB FC FD FE FF
0000000 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f
0000020 10 11 1f 20 fa fb fc fd fe ff
0000032
I use 'od' to do the binary to ascii conversion so I can print the
result. But you can also redirect the output in a file and load it in
emacs (in hexl-mode) to double check.
Massaging of the value can be done before the printf as in :
awk --non-decimal-data 'BEGIN {RS=" "} {x=$0; x++; x="0x"x;
printf("%c", 0+x);}'|od -t x1
1 2 3
0000000 02 03 04
/s
On Fri, 30 Jul 2004 19:40:51 -0700 (PDT), Dwight K. Elvey
<dwight.elvey(a)amd.com> wrote:
>
> >Date: Sat, 31 Jul 2004 04:16:09 +0200
> >From: "Stephane Tsacas" <stephane.tsacas(a)gmail.com>
> >To: "Dwight K. Elvey" <dwight.elvey(a)amd.com>om>, "General
Discussion: On-Topic
and
Off-Topic
Posts" <cctalk(a)classiccmp.org>
Subject: Re: OT-ish - converting hex output to
binary on a Unix platform
awk --non-decimal-data 'BEGIN {RS=" "} {x="0x"$0; printf("%d
", x)}'
0 1 2 3 4 5 6 7 8 9 A B C D E F 10 11 12 1F 20 FC FD FE FF
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 31 32 252 253 254 255
better ?
Hi
I think your still missing the point. Your printout is
all in ascii. If things were working as expected the
number '31' hex would display as '1' when printed. Many hex
numbers would not even display. It looks like the variable
is now correct but you need to write it as the byte value
to a file not convert it to the decimal printed
as ascii digits. 255 is the binary values that are 00110010
00110101 00110101. This is 3 values not the one value 11111111.
I think you are still confusing the byte with the displayed
value.
Am I making sense?
Dwight
On Fri, 30 Jul 2004 18:26:12 -0700 (PDT), Dwight K. Elvey
<dwight.elvey(a)amd.com>
wrote:
...
I'm not sure this is what he is looking for.
I think
he wants the hex number converted to a byte value
not just printed in ascii as a binary value.
Dwight