Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

USPS Intelligent Barcode - binary data manipulations

by elfpen (Novice)
on Sep 09, 2010 at 20:46 UTC ( [id://859562]=perlquestion: print w/replies, xml ) Need Help??

elfpen has asked for the wisdom of the Perl Monks concerning the following question:

I am looking at implementing the USPS Intelligent Mail Barcode algorithm in perl.

My first choice would be to find where someone has already done that, but no luck so far.

That leaves me with the need for some wisdom in handling a 13-byte data chunk that has both binary and decimal operations applied to it. Any advice?

Specification for the algorithm is at USPS Intelligent Barcode Page, then click on "Intelligent Mail Barcode Specification".



later
I have my implementation. It uses BigInt. It can be found at http://www.w0ep.us/IMBar.pl.
30-JAN-2011 found a bug in my implementation, uploading the newest to http://www.w0ep.us/IMBar.pl.
28-NOV-2011 another bug reported by a user. New version 1.4 as of today.
  • Comment on USPS Intelligent Barcode - binary data manipulations

Replies are listed 'Best First'.
Re: USPS Intelligent Barcode - binary data manipulations
by BrowserUk (Patriarch) on Sep 10, 2010 at 11:30 UTC

    I take it back!

    Having looked in more detail at the specification this morning, I see why you're having problems working out how to do this.

    This is one of those really nasty pieces of mainframe/COBOL-esque encoding, that requires BCD math on a fixed length BCD field. (COBOL: PIC 9(13) COMP).

    Perl's pack & unpack don't have anything to handle this directly, and even on a 64-bit machine, integer math simply isn't capable of handling 13-byte numbers.

    One way might be to drop into Inline::C and inline assembler (or Inline::Asm ) and use the vestigal BCD opcodes. (Though MS 64-bit compilers don't support inline assembler.)

    There are also some weird x64 opcodes that treat an 80-bit floating point register as a 17 digit BCD value that might be pressed into service for this.

    Perhaps the easiest and most portable way would be to use Math::BigInt to do the math; as_hex() to get it out of BigInt format; and then pack 'H26' to creat the binary string.

    Or download the USPS libraries and link them from XS.

    I think that the BigInt method would be easiest. Let us know if you need help with that?


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re: USPS Intelligent Barcode - binary data manipulations
by Corion (Patriarch) on Sep 09, 2010 at 20:56 UTC

    I couldn't find the "algorithm" online, and I wonder what you mean by "both, binary and decimal operations".

    I found a free PostNet Postscript font via a mailing list post at PostNetJHC. Maybe you can simply use that to print the barcodes you want.

      Added a link to find the spec on my original post. --
Re: USPS Intelligent Barcode - binary data manipulations
by BrowserUk (Patriarch) on Sep 09, 2010 at 22:58 UTC

    The specification seems very clear. What bit are you having trouble with?

Re: USPS Intelligent Barcode - binary data manipulations
by merlyn (Sage) on Sep 10, 2010 at 16:52 UTC
    A quick cpan search with "USPS Barcode" revealed PostScript::MailLabels. Did you already check that out?

    -- Randal L. Schwartz, Perl hacker

    The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119.

      The bar codes it can produce are not the Intelligent Mail (65-bar) type.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://859562]
Approved by AnomalousMonk
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (1)
As of 2024-04-25 03:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found