OT-ish - converting hex output to binary on a Unix platform

From: Stephane Tsacas <stephane.tsacas_at_gmail.com>
Date: Fri Jul 30 20:00:59 2004

I guess you have hex digit as input, not prefixed by 0x (if they are,
remove the string "0x" from the x= statement. Maybe that code might
help :

awk --non-decimal-data 'BEGIN {RS=" ";} {x="0x"$0; s=""; while (x > 0)
 { s=and(x,1)""s; x=rshift(x,1); } print s}'

0 1 2 3 4 5 6 7 8 9 a b c d e f as input will print :
0
1
10
11
100
101
110
111
1000
1001
1010
1011
1100
1101
1110
1111

you can put your own code after the x= statement I guess.
Stephane

On Fri, 30 Jul 2004 22:42:51 +0000, Jules Richardson
<julesrichardsonuk_at_yahoo.co.uk> wrote:
> On Fri, 2004-07-30 at 21:41, Tony Duell wrote:
...
> That's what I've ended up with actually - at least for going from hex to
> binary. Hexdump handles the other way around quite happily!
...
> I couldn't figure out a good way of doing this with awk - I'm capable of
> writing some awk to format output, but not to actual interpret data, do
> calculations with it, and spit it out in a different format...
...
Received on Fri Jul 30 2004 - 20:00:59 BST

This archive was generated by hypermail 2.3.0 : Fri Oct 10 2014 - 23:36:53 BST