# Matrix 2 of 5

Matrix 2 of 5 (also known as Code 2 of 5 Matrix.) is a variable length, discrete, two width symbology. Matrix 2 of 5 is a subset of two-out-of-five codes. Unlike Industrial 2 of 5 code, Matrix 2 of 5 can encode data not only with black bars but with white spaces.
Matrix 2 of 5 was developed in 1970-х by Nieaf Co. in The Netherlands and commonly was uses for warehouse sorting, photo finishing, and airline ticket marking.
Matrix 2 of 5 can encode only digits 0-9. Matrix 2 of 5 can include optional check digit. Most of barcode readers support this symbology.

## Encoding

Matrix 2 of 5 is a subset of two-out-of-five codes family and uses wide and narrow elements for encoding. Unlike previously developed Industrial 2 of 5 it uses both black bars and white spaces for data encoding. However, it has lower density then Interleaved 2 of 5 code, because it is discrete symbology and requires additional space between data patterns. Main advantage over Interleaved 2 of 5 codes is ability to encode odd number of characters in message.
Matrix 2 of 5 encodes only digits from 0 to 9 in three black bars and two white spaces, with every data pattern split by additional white space. Matrix 2 of 5 could include optional checksum character which is added to the end of the barcode.
Matrix 2 of 5 features:
* character set is a number (0-9);
* encoding density moderate: barcode length on 11% longer than Interleaved 2 of 5 symbology and on 82% than Code 128;
* variable length of symbol;
* can include optional checking character.
Four starting bars and spaces in pattern have own weights which encode value of the symbol (except zero). Also, last black bar is used as parity bit to avoid single error. Value of the symbol is a sum of nonzero weights of four first pattern elements.
Matrix 2 of 5 digits encoding :
| Digit | Bar weight | Bar weight | Bar weight | Bar weight | Bar weight | Bars | Encoding | Mnemonic (using weights) |
| Digit | 1 | 2 | 4 | 7 | Parity Bit | Bars | Encoding | Mnemonic (using weights) |
| 0 | 0 | 0 | 1 | 1 | 0 | |▮ | | NNWWN | 4+7=11, replaced by 0 |
| 1 | 1 | 0 | 0 | 0 | 1 | ▮|▮ | WNNNW | 1+0=1 |
| 2 | 0 | 1 | 0 | 0 | 1 | | |▮ | NWNNW | 0+2=2 |
| 3 | 1 | 1 | 0 | 0 | 0 | ▮ || | WWNNN | 1+2=3 |
| 4 | 0 | 0 | 1 | 0 | 1 | |▮▮ | NNWNW | 4+0=4 |
| 5 | 1 | 0 | 1 | 0 | 0 | ▮▮| | WNWNN | 1+4=5 |
| 6 | 0 | 1 | 1 | 0 | 0 | | ▮| | NWWNN | 2+4=6 |
| 7 | 0 | 0 | 0 | 1 | 1 | || ▮ | NNNWW | 7+0=7 |
| 8 | 1 | 0 | 0 | 1 | 0 | ▮| | | WNNWN | 1+7=8 |
| 9 | 0 | 1 | 0 | 1 | 0 | | | | | NWNWN | 2+7=9 |
N - narrow black bar or white space. W - wide black bar or white space. Narrow to wide components difference could be from 1/3 to 2/5.
Matrix 2 of 5 Start/Stop values :
| Value | Bars | Encoding |
| Start | ▮|| | WNNNN |
| Stop | ▮|| | WNNNN |
The barcode has the following physical structure: 1. Quiet zone 10X wide 2. Start character 3. Variable length digit characters, properly encoded 4. Optional check digit 5. Stop character 6. Quiet zone 10X wide

## Checksum

Matrix 2 of 5 may include an optional check digit which is calculated as mod 10/3 checksum. Because specification of Matrix 2 of 5 does not require checksum any other checksum types could be used with the symbology. However mod 10/3 checksum is most common. $x_{check}=10-((3x_{1}+x_{2}+3x_{3}+x_{4}+\cdots +x_{2n}+3x_{2n+1}){\pmod {10}})$, where $x_{1}$ is the most right data digit.
Example for the first 6 digits 423456:
Calculating the Industrial 2 of 5 checksum :
| Digit | 4 | 2 | 3 | 4 | 5 | 6 |
| Position | $x_{6}$ | $x_{5}$ | $x_{4}$ | $x_{3}$ | $x_{2}$ | $x_{1}$ |
| Weight | 1 | 3 | 1 | 3 | 1 | 3 |
| Weighted sum | 4 | 6 | 3 | 12 | 5 | 18 |
| Check digit | 10 - (48 mod 10) = 2 | 10 - (48 mod 10) = 2 | 10 - (48 mod 10) = 2 | 10 - (48 mod 10) = 2 | 10 - (48 mod 10) = 2 | 10 - (48 mod 10) = 2 |
Result: 4234562 barcode

## Datalogic 2 of 5

Data Logic 2 of 5 (also known as Code 2 of 5 Datalogic, China Post Code) is proprietary Chinese version of Matrix 2 of 5 symbology developed by Datalogic. It has difference from Matrix 2 of 5 code only in start/stop patterns usage and, in this way, it has all advantages and issues of Matrix 2 of 5.
Datalogic 2 of 5 was used mostly in Chinese Postal Services. Some readers currently still support this symbology
Datalogic 2 of 5 Start/Stop values :
| Value | Bars | Encoding |
| Start | || | NNN |
| Stop | ▮| | WNN |
N - narrow black bar or white space. W - wide black bar or white space.