Bar Codes Lots of different ones. Most (but not all) based on a fixed-width representation. Most contain some sort of error correction. Many 2D versions exist Code that is used for products in stores is UPC-A (Uniform Product Code A) Allows representation of digits 0-9. Basic element is a field of width 7, which contains Dark and light bars of relative length 1, 2, 3, and 4 Each code consists of 2 light and 2 dark bars whose width sums to 7 units Each digit has two representations, a "light dark light dark" one used on the left half of the code, and a "dark light dark light" one used in the right half of the code. The two codes for a digit are the same except that light and dark are interchanged. This setup permits codes to be read unambiguously both right to left and left to right The patterns can be represented by a 7 place bit string xxxxxxx. For bar codes beginning with 0 and ending with 1 0xxxxx1, there are 6 interior locations where a switch from 0 to 1 or 1 to 0 could occur. We need to select 3 of these, so there are 6 choose 3 = 20 possibilities. To provide an internal error check, the odd parity ones are selected. this provides a distance of at least 2 between valid codes. The right codes are thus automatically even parity. Actual digit codes (light dark light dark versions) 0 represents light, 1 dark in the following. 0 = 0001101 1 = 0011001 2 = 0010011 3 = 0111101 4 = 0100011 5 = 0110001 6 = 0101111 7 = 0111011 8 = 0110111 9 = 0001011 The full bar code consists of the following, in sequence, from left to right. 1. The length 3 "start/stop code" 101 2. The left digit code for 0 0001101 3. Five length 7 left digit fields Oxxxxx1 * 5 4. The length 5 "center code" 01010 5. Five length 7 right digit fields 1yyyyy0 * 5 6. A mod 10 checksum right digit 1zzzzz0 7. The length 3 "start/stop code" 101 Total length 3 + 6*7 + 5 + 6*7 + 3 = 95 The Scanning process is fairly involved signal processing. Start/stop codes provide indication of presence of code and basic unit length. With this established, an attempt is made to interpret the rest of the scan. Process fails if center and stop codes do not show up where expected, if any digit on the left does not meet the left parity check, if any digit on the right does not meet the right parity check, or if the mod 10 checksum is incorrect. Various garbage (e.g. printing) might look like a start code. Given that this occurs, and that 92 additional slots are then "digitized" 0 or 1, we might compute the probability of interpreting random stuff as a bar code. (The signal processing actually needs to be a bit more flexible than this but go with this model for now) Of the 2^7 = 128 possible combinations in a 7 slot field, only 10 of them are valid digit codes (once the direction has been established). Thus we have Probability of the stop code showing up where expected is 1/2^3 = 1/8 Probability of the center code showing up where expected is 1/2^5 = 1/32 Probability of all 12 digit field being valid for a selected direction is (10/2^7)^12 Probability of initial digit being 0 is 1/10 Probability of checksum being correct is 1/10 Number of ways of attempting to interpret code is 2 (directions). Multiplying all this we get the probability of garbage being mis-recognized as a bar code p = 2 * 10^12 / (2^8 * 2^84 * 100) ~= 2 * 10^12 / (4 * 10^30 * 10^2) or on the order of one in 10^20. Not very high. Still, with (say) 10^9 people each purchasing a few items a day, and all sorts of garbage being hit as the laser beam sweeps around it may have happened once or twice in the last 20 years, especially with our model of signal processing being a bit tight ... On the other hand, the probability of a locally damaged barcode being misread is significantly higher. If we have damage that effects more than one adjacent bit, then the probability that a damaged region will be a valid digit code is approximately 10/128 and the probability that the checksum will be correct is 1 in 10, so there is a probability on the order of 1/100 that some valid code will be obtained. This is not quite as much a problem as it sounds. First, most scanners make multiple passes over slightly different parts of the barcode, and expect the results to agree. Also, the changed code may not be a valid item at a particular store. ----------------------------------------------------------------- Other bar codes * Two out of Five: Groups of 5 dark bars, 2 of them wide. Gives 10 codes, enough for the digits. * Code 39: Five dark bars, two of them wide, one of the 4 interior spaces also wide. Gives 40 codes, enough for digits, single case letters, and a few extra characters. Augmenting with codes having all narrow black lines and 3 wide spaces (same width field) gives 4 additional code characters. * US Postal code: 2 out of five code using tall and short lines instead of wide and narrow ones. * ISBN (International Standard Book Number): Like UPC-A except a different checksum (base on mod 11) is used, and the first digit is not 0. * Code 128: Patterns of length 11 with 3 bars and spaces, with bars and spaces at most 4 in width. Permits (almost) full 7-bit ASCII to be encoded. 2D bar codes * PDF 417: Error correcting code based on Reed-Solomon algorithm. In public domain, used as substitute for stamps on letters and packages. * MaxiCode: Matrix code developed by UPS in 1992. Can encode about 100 ASCII characters in 1 square inch. Can correct errors with damage to 25% of surface area. * Datastrip Code: Appeared in early PC magazines as a method for downloading simple programs (before the internet existed). Could achieve data densities of 20-150 bytes/square centimeter.