First of all, please provide something runnable in your future questions instead of forcing us to do that work.
use strict;
use warnings qw( all );
my @binimage = ( "\x00", "\x00", "\x00", "\x00", "\x00", "\x90" );
my $nextrow = 5;
my $col = 0;
my $subcol = 0;
for my $index (0..5) {
my $thisrow = $nextrow - $index;
print "processing row/column/bit $thisrow/$col/$subcol: " . substr
+($binimage[$thisrow], $col, 1) . "\n";
printf ("Incoming byte is %d/%x/%8b/%s. Test bitmask is %d/%x/%8b
+/%s.\n",
substr($binimage[$thisrow], $col, 1),
substr($binimage[$thisrow], $col, 1),
substr($binimage[$thisrow], $col, 1),
unpack('B8',substr($binimage[$thisrow], $col, 1)),
2**(7-$subcol),
2**(7-$subcol),
2**(7-$subcol),
unpack('B8', 2**(7-$subcol)));
printf "%s\n", ((substr($binimage[$thisrow], $col, 1)) & 2**(7-$su
+bcol))? "1" : "0";
}
Secondly, ALWAYS USE use strict; use warnings qw( all );!!! This is the output of the above program:
printf (...) interpreted as function at a.pl line 13.
processing row/column/bit 5/0/0: ▒
Argument "M-^P" isn't numeric in printf at a.pl line 13.
Argument "M-^P" isn't numeric in printf at a.pl line 13.
Argument "M-^P" isn't numeric in printf at a.pl line 13.
Incoming byte is 0/0/ 0/10010000. Test bitmask is 128/80/100000
+00/00110001.
Argument "M-^P" isn't numeric in bitwise and (&) at a.pl line 23.
0
processing row/column/bit 4/0/0:
Argument "\0" isn't numeric in printf at a.pl line 13.
Argument "\0" isn't numeric in printf at a.pl line 13.
Argument "\0" isn't numeric in printf at a.pl line 13.
Incoming byte is 0/0/ 0/00000000. Test bitmask is 128/80/100000
+00/00110001.
Argument "\0" isn't numeric in bitwise and (&) at a.pl line 23.
0
processing row/column/bit 3/0/0:
Argument "\0" isn't numeric in printf at a.pl line 13.
Argument "\0" isn't numeric in printf at a.pl line 13.
Argument "\0" isn't numeric in printf at a.pl line 13.
Incoming byte is 0/0/ 0/00000000. Test bitmask is 128/80/100000
+00/00110001.
Argument "\0" isn't numeric in bitwise and (&) at a.pl line 23.
0
processing row/column/bit 2/0/0:
Argument "\0" isn't numeric in printf at a.pl line 13.
Argument "\0" isn't numeric in printf at a.pl line 13.
Argument "\0" isn't numeric in printf at a.pl line 13.
Incoming byte is 0/0/ 0/00000000. Test bitmask is 128/80/100000
+00/00110001.
Argument "\0" isn't numeric in bitwise and (&) at a.pl line 23.
0
processing row/column/bit 1/0/0:
Argument "\0" isn't numeric in printf at a.pl line 13.
Argument "\0" isn't numeric in printf at a.pl line 13.
Argument "\0" isn't numeric in printf at a.pl line 13.
Incoming byte is 0/0/ 0/00000000. Test bitmask is 128/80/100000
+00/00110001.
Argument "\0" isn't numeric in bitwise and (&) at a.pl line 23.
0
processing row/column/bit 0/0/0:
Argument "\0" isn't numeric in printf at a.pl line 13.
Argument "\0" isn't numeric in printf at a.pl line 13.
Argument "\0" isn't numeric in printf at a.pl line 13.
Incoming byte is 0/0/ 0/00000000. Test bitmask is 128/80/100000
+00/00110001.
Argument "\0" isn't numeric in bitwise and (&) at a.pl line 23.
0
You are repeatedly using the string resulting from "\x90" as a number, but it's not.
You are repeatedly using the string resulting from "\x00" as a number, but it's not.
Basically, everywhere you have
substr($binimage[$thisrow], $col, 1)
you should have
ord(substr($binimage[$thisrow], $col, 1))
(Inside unpack 'B8' is the exception. That one does expect a string.)
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.