[clug] command to reverse 'xxd -b'??
steve jenkin
sjenkin at canb.auug.org.au
Tue Oct 29 01:22:23 MDT 2013
Hal,
Nice... Didn't think of a bash table.
Cheers!
steve
Hal Ashburner wrote on 29/10/13 4:10 PM:
> Hey Steve,
>
> I'd just use a lookup table of size 16 and treat it nibble by nibble
> Can do this in bash if you don't want to go the C route.
>
> #!/bin/bash
> set -e
> set -u
>
>
> declare -a table
> table["0000"]="0";
> table["0001"]="1";
> table["0010"]="2";
> table["0011"]="3";
> table["0100"]="4";
> table["0101"]="5";
> table["0110"]="6";
> table["0111"]="7";
> table["1000"]="8";
> table["1001"]="9";
> table["1010"]="a";
> table["1011"]="b";
> table["1100"]="c";
> table["1101"]="d";
> table["1110"]="e";
> table["1111"]="f";
>
>
> echo \${table[1010]} = ${table[1010]} == a
>
>
> loop, incrementing in units of 4.
> with something like:
> echo ${input_line:$position:4}
>
> and if it's not divisible by 4 you have a different problem ;)
>
> (I think I'd go the C route myself unless I was wanting to play with a
> different language - x86-64 asm using AVX instructions might be fun if
> you've got a Sandy Bridge or newer core i7 CPU)
--
Steve Jenkin, Info Tech, Systems and Design Specialist.
0412 786 915 (+61 412 786 915)
PO Box 48, Kippax ACT 2615, AUSTRALIA
sjenkin at canb.auug.org.au http://members.tip.net.au/~sjenkin
More information about the linux
mailing list