Question

I am investigating encoding of date information into a linear barcode that must be as short as possible. One idea we have had is encoding date information rather than using the ASCII characters for the date numerals.

  1. The earliest date to be encoded is 01-JAN-2009
  2. Date must be encoded using printable ASCII characters
Was it helpful?

Solution

If only the date matters (not the time):

 Take the date to be encoded.
 Subtract 1-1-2009 from it
 Get the amount of elapsed days.

To encode this number as a printable sequence of ascii chars(ascii 48-127) do the following

pseudo code:

 const int ASCIILOWRANGE = 48
 const int ASCIIHIGHRANGE = 126
 const char ASCIIENDMARKER = 127;


 String convertToAscii(int numberOfDays)
 {
       String output = "";

       while(numberOfDays>0)
       {
           output += (char) ASCIILOWRANGE + numberOfDays % (ASCIIHIGHRANGE-ASCIILOWRANGE);
           numberOfDays /= (ASCIIHIGHRANGE-ASCIILOWRANGE);
       }
       output += ASCIIENDMARKER ;
       return output;
 }

 //decoder
 int convertToDays(String ascii)
 {
      char rightmost;
      int numberOfDays = 0;
      while(ascii.length>0)
      {
       rightmost = ascii[0];
           if(rightmost == ASCIIENDMARKER ) break; //ready

           numberOfDays *= (rightmost - ASCIILOWRANGE) * (ASCIIHIGHRANGE-ASCIILOWRANGE);
           ascii = ascii.substr(1); //remove rightmost char from string
      }
      return numberOfDays ;
 }

this way of encoding is the most dense. Since it encodes upto 96 days into the future in just 2 chars. 9216 days, in 3 chars, 884736 days in 4 chars.

OTHER TIPS

Use the date itself: 01/01/2009 is a perfectly acceptable barcode under the Code39 style barcode.

If you don't mind a bit of processing logic during read, then you can do things like remove the "/" or whatever separator character you use.

Basically you would encode something like, "01012009" into the barcode, and then have the decode process just read the first two numbers as the month, the next two as the day, and the last 4 as the year. Since they're straight ascii it will work without any really hard processing.

A second alternative is to have 01-Jan-2009 as your "0" date, and then just encode the number of days since then. At which the decoding process would be to read the number, and then add that many days to 1/1/09. This would work that, Jan/5/2009 would be encoded as a "4" then when you wanted to read the date back out, you'd add 4 to Jan/1/09 to get Jan/5/09.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top