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
you should havesubstr($binimage[$thisrow], $col, 1)
ord(substr($binimage[$thisrow], $col, 1))
(Inside unpack 'B8' is the exception. That one does expect a string.)
In reply to Re: I've muddled my bit and byte formats.
by ikegami
in thread I've muddled my bit and byte formats.
by murrayn
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |