If you used strict and warnings then you'd probably see output from your code along the lines of:
Line: 0xf0 0x0f 0x01 0x02 0x03 0x04 0x05 0x06 Extracted numbers : 0xf0|0x0f|0x01|0x02|0x03|0x04|0x05|0x06 Argument "0xf0" isn't numeric in bitwise and (&) at c:\test\junk.pl li +ne 12, <> line 1. Argument "0x0f" isn't numeric in bitwise and (&) at c:\test\junk.pl li +ne 12, <> line 1. Argument "0x01" isn't numeric in bitwise and (&) at c:\test\junk.pl li +ne 12, <> line 1. Argument "0x02" isn't numeric in bitwise and (&) at c:\test\junk.pl li +ne 12, <> line 1. Argument "0x03" isn't numeric in bitwise and (&) at c:\test\junk.pl li +ne 12, <> line 1. Argument "0x04" isn't numeric in bitwise and (&) at c:\test\junk.pl li +ne 12, <> line 1. Argument "0x05" isn't numeric in bitwise and (&) at c:\test\junk.pl li +ne 12, <> line 1. Argument "0x06" isn't numeric in bitwise and (&) at c:\test\junk.pl li +ne 12, <> line 1. Changed fonts : 0|0|0|0|0|0|0|0
Which would identify that whilst Perl knows to convert hex encoded barewords in source code into numbers, it does not automatically do the same for hex strings read in from external sources. Ie. The problem lies with your data parsing not the code I posted.
The simplest fix is to use the built-in hex function to convert them to numbers:
open(INPUT, "< ./vrsticni_fonti.txt") or die "Couldn't open ./vrsticni_fonti.txt for reading: $!\n"; my $line; while (<INPUT>) { $line = $_ ; print "Line: $line \n"; # my @rows = ( 0x04, 0x04, 0x04, 0x04, 0x00, 0x00, 0x04, 0x00 ); my @rows = ($line =~ m/(0x[a-fA-F0-9]+)/g); ## convert the hex strings to numbers. @rows = map hex, @rows; print "Extracted numbers : " . join("|", @rows) . "\n"; my @cols = (0) x 8; for my $c ( 0 .. 7 ){ $rows[ $_ ] & 1 << $c and $cols[ $c ] |= 1 << $_ for 0 .. 7; } print "Changed fonts : " . join("|", @cols) . "\n"; # printf "0x%02x\n", $_ for @cols; } close(INPUT); __END__ Line: 0xf0 0x0f 0x01 0x02 0x03 0x04 0x05 0x06 Extracted numbers : 240|15|1|2|3|4|5|6 Changed fonts : 86|154|226|2|1|1|1|1
Note: The extracted numbers now display as numbers and the transformed output is no longer zeroes.
In reply to Re^3: Font bitmaps manipulation in perl (transposing row like font description to column like)....
by BrowserUk
in thread Font bitmaps manipulation in perl (transposing row like font description to column like)....
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |