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.

In reply to Re^4: Testing & Using Bits by Aim9b
in thread Testing & Using Bits by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.