It should give you an idea how to solve it.
I do not have a Solaris box at hand and I do not know what shell you use - thats why I said untested. You'll have to put some effort into it and find the correct syntax for your environment.
Here is a working solution based on cero suggestion, although extremely inefficient. Shell scripting is not really adapted to this kind of tasks.
od -An -v -t d1 yourbinary |
while read line ; do
for byte in $line ; do
if [ $byte -lt 0 ] ; then byte=$((byte+256)); fi
printf "%08.8s" $(echo "ibase=10;obase=2;$byte"|bc)
done
done
@cjcox: your code is indeed much better but has a several issues with Solaris.
sed: command garbled: a\p
With the a\p syntax fixed, the output is still broken:
0111111101000101empty stack01000110000000010000000100000001000000000000000000000
00000000000000000000000000000000000000000000000000011 is unimplemented0000001000
00000000000011000000000000000100000000000000000000000000000000142 is unimplement
ed000000000101000010000011010000000000000000000000000011 is unimplemented1000100
00010001100000000000000000000000000000000000000000000000000110100000000000010000
0000000000000011000000000001010000000000011 is unimplemented00010111000000000001
01010000000000000110000000000000000000000000001101000000000000000000000000000011
010000000000000001010000100011 is unimplemented000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000010100000000000000000000000
011 is unimplemented000000000000000000000000000000000000001100000000000000000000
0000111101000000000000000000000000000000000000000000000000000000000011 is unimpl
emented0000000000000000000000000000000000010001000000000000000000000000000000000
000000000000000000000000000010000000000000000000000000011 is unimplemented000000
00000000000000000000000000000000010000000000000000000000000000000000000000000000
00000000000000000000000000000001010000100011 is unimplemented0000000000000000000
00000000000000010142 is unimplemented000100000000000000000010142 is unimplemente
d000100000000000000000000010100000000000000000000000011 is unimplemented00000000
00000000000000010000000000000001000000000000000000000000000000000010000000000000
000000000000000000100000000001100000100011 is unimplemented000000000000000000000
000hex digit > 16out of stack space145 is unimplementedhex digit > 16out of stack
Hi jlliagre...
OK, using shell and od only in OSX 10.7.5 default terminal limited to 32 bytes for this basic DEMO. It can easily be enhanced upon...
(Both hexdump and od are used in AudioScope.sh as CygWin does not have hexdump.)
#!/bin/sh
# bin.sh
dd if=/dev/urandom of=/tmp/binary bs=32 count=1
for subscript in {0..31}
do
num=`od -An -N1 -j$subscript -tu /tmp/binary`
echo "Decimal number ="$num"..."
echo "ibase=10; obase=2; $num" | bc
done
Results:-
Last login: Tue Oct 20 14:00:40 on ttys000
AMIGA:barrywalker~> cd Desktop/Code/Shell
AMIGA:barrywalker~/Desktop/Code/Shell> ./bin.sh
1+0 records in
1+0 records out
32 bytes transferred in 0.000031 secs (1032444 bytes/sec)
Decimal number = 48 ...
110000
Decimal number = 82 ...
1010010
Decimal number = 118 ...
1110110
Decimal number = 152 ...
10011000
Decimal number = 42 ...
101010
Decimal number = 11 ...
1011
Decimal number = 185 ...
10111001
Decimal number = 185 ...
10111001
Decimal number = 101 ...
1100101
Decimal number = 238 ...
11101110
Decimal number = 6 ...
110
Decimal number = 11 ...
1011
Decimal number = 87 ...
1010111
Decimal number = 62 ...
111110
Decimal number = 12 ...
1100
Decimal number = 94 ...
1011110
Decimal number = 1 ...
1
Decimal number = 142 ...
10001110
Decimal number = 233 ...
11101001
Decimal number = 102 ...
1100110
Decimal number = 57 ...
111001
Decimal number = 39 ...
100111
Decimal number = 149 ...
10010101
Decimal number = 134 ...
10000110
Decimal number = 46 ...
101110
Decimal number = 94 ...
1011110
Decimal number = 238 ...
11101110
Decimal number = 200 ...
11001000
Decimal number = 111 ...
1101111
Decimal number = 38 ...
100110
Decimal number = 191 ...
10111111
Decimal number = 248 ...
11111000
AMIGA:barrywalker~/Desktop/Code/Shell>
With the correct shebang ("#!/bin/bash" as you use bash specific features), your script works under Solaris but is missing some code to answer the original question. Moreover, opening then skipping to each possible offset the input file for every byte in it is a very conterproductive approach.