OK, I guess there's just no getting around it... ;-) Here's my code...
# !perl DebugBCD.pl
open (inFILE, "<C:/Dev/Perl_Dev/ItemExp/TESTFILE.DAT") ||
die "Cannot open file\n";
# The first 6 bytes of my test file contain the 12 digit UPC Barcode 1
+23456789910
binmode (inFILE);
seek (inFILE,0,0);
read (inFILE,$inBuf,6);
print "Len=".length($inBuf)." Raw Data = $inBuf \n"; # This prints t
+he graphics
$Test = DecodeBCD($inBuf);
print $Test; # This prints 48 48 52 48 I expected
+ 1 2 3 4
close inFile;
sub DecodeBCD {
my ($i,@lo,@hi,$Byte,$Bits,@pairs);
my $Hi,$Low;
my $LoMask = 15;
my $HiMask = 240;
my $Zone = 0x30;
for ($i = 0; $i < 2; $i++)
{
$Byte = substr($_[0],$i,1);
$lo[$i] = ($Byte & $LoMask) | $Zone; # These OR statement
+s seem to
$hi[$i] = (($Byte & $HiMask) >> 4) | $Zone; # result in JUST the
+ $Zone piece,
$pairs[$i] = join("",$lo[$i],$hi[$i]); # Implying that the
+& result is Zero.
print "\nLo $i=".$lo[$i]." Hi $i=".$hi[$i]." $pairs[$i]\n
+";
}
print "(@pairs)\n";
chomp ($Dummy = <STDIN>);
join('',@pairs);
}
Please try to keep the laughter to a dull roar.
|