Ejemplo n.º 1
0
        private void AusPost()
        {
            /* Handles Australia Posts's 4 State Codes
             * The contents of data pattern conform to the following standard:
             * 0 = Tracker, Ascender and Descender
             * 1 = Tracker and Ascender
             * 2 = Tracker and Descender
             * 3 = Tracker only */

            int             inputLength  = barcodeData.Length;
            StringBuilder   barPattern   = new StringBuilder();
            AusPostEncoding encodingMode = AusPostEncoding.Numeric;
            string          fcc          = String.Empty; // Format Control Code
            string          dpid         = String.Empty; // Delivery Point ID.
            string          cif          = string.Empty; // Customer Information Field.
            int             cifLength    = 0;

            // Do all of the length and integrity checking first.
            if (inputLength >= 10)
            {
                // Check valid FCC and DPID.
                for (int i = 0; i < 10; i++)
                {
                    if (CharacterSets.NumberOnlySet.IndexOf(barcodeData[i]) == -1)
                    {
                        throw new InvalidDataException("AusPost: FCC and DPID must be numeric data.");
                    }
                }

                fcc  = new string(barcodeData, 0, 2);
                dpid = new string(barcodeData, 2, 8);

                // Check for CIF.
                if (inputLength > 10)
                {
                    cif       = new string(barcodeData, 10, inputLength - 10);
                    cifLength = cif.Length;
                }
            }

            else
            {
                throw new InvalidDataLengthException("AusPost: Input data wrong length.");
            }

            if (symbolId == Symbology.AusPostStandard)
            {
                if (fcc != "11" && fcc != "59" && fcc != "62")
                {
                    throw new InvalidDataFormatException("AusPost Standard: Invalid Format Control Code (" + fcc + ").");
                }

                if (fcc == "11" && inputLength != 10)
                {
                    throw new InvalidDataLengthException("AusPost Standard: Input is wrong length for Format Control Code 11.");
                }

                if (fcc == "59")
                {
                    if (cifLength > 5 && cifLength < 9)
                    {
                        for (int i = 0; i < cifLength; i++)
                        {
                            if (CharacterSets.NumberOnlySet.IndexOf(cif[i]) == -1)
                            {
                                throw new InvalidDataException("AusPost Standard: Invalid data for Numeric encoding.");
                            }
                        }

                        encodingMode = AusPostEncoding.Numeric;
                    }

                    else if (cifLength < 6)
                    {
                        for (int i = 0; i < cifLength; i++)
                        {
                            if (CharacterSets.AusPostSet.IndexOf(cif[i]) == -1)
                            {
                                throw new InvalidDataException("AusPost Standard: Invalid data for Character encoding.");
                            }
                        }

                        encodingMode = AusPostEncoding.Character;
                    }

                    else
                    {
                        throw new InvalidDataLengthException("AusPost Standard: Input is wrong length for Customer Information Field.");
                    }
                }

                if (fcc == "62")
                {
                    if (cifLength > 10 && cifLength < 16)
                    {
                        for (int i = 0; i < cifLength; i++)
                        {
                            if (CharacterSets.NumberOnlySet.IndexOf(cif[i]) == -1)
                            {
                                throw new InvalidDataException("AusPost Standard: Invalid data for Numeric encoding.");
                            }
                        }

                        encodingMode = AusPostEncoding.Numeric;
                    }

                    else if (cifLength < 11)
                    {
                        for (int i = 0; i < cifLength; i++)
                        {
                            if (CharacterSets.AusPostSet.IndexOf(cif[i]) == -1)
                            {
                                throw new InvalidDataException("AusPost Standard: Invalid data for Character encoding.");
                            }
                        }

                        encodingMode = AusPostEncoding.Character;
                    }

                    else
                    {
                        throw new InvalidDataLengthException("AusPost Standard: Input is wrong length for Customer Information Field.");
                    }
                }
            }

            else
            {
                if (inputLength != 10)
                {
                    throw new InvalidDataLengthException("AusPost: Input is wrong length for selected AusPost symbol.");
                }

                switch (symbolId)
                {
                case Symbology.AusPostReplyPaid:
                    if (fcc != "45")
                    {
                        throw new InvalidDataException("AusPost Reply Paid: Invalid Format Control Code.");
                    }
                    break;

                case Symbology.AusPostRouting:
                    if (fcc != "87")
                    {
                        throw new InvalidDataException("AusPost Routing: Invalid Format Control Code.");
                    }
                    break;

                case Symbology.AusPostRedirect:
                    if (fcc != "92")
                    {
                        throw new InvalidDataException("AusPost Redirect: Invalid Format Control Code.");
                    }
                    break;
                }
            }

            // Encode the Format Control Code.
            for (int i = 0; i < 2; i++)
            {
                int index = CharacterSets.NumberOnlySet.IndexOf(fcc[i]);
                barPattern.Append(AusNTable[index]);
            }

            // Delivery Point Identifier.
            for (int i = 0; i < 8; i++)
            {
                int index = CharacterSets.NumberOnlySet.IndexOf(dpid[i]);
                barPattern.Append(AusNTable[index]);
            }

            if (encodingMode == AusPostEncoding.Character)
            {
                for (int i = 0; i < cif.Length; i++)
                {
                    int index = CharacterSets.AusPostSet.IndexOf(cif[i]);
                    barPattern.Append(AusCTable[index]);
                }
            }

            else
            {
                for (int i = 0; i < cif.Length; i++)
                {
                    int index = CharacterSets.NumberOnlySet.IndexOf(cif[i]);
                    barPattern.Append(AusNTable[index]);
                }
            }

            // Filler bars.
            int patternLength = barPattern.Length;

            if (fcc == "59" && patternLength < 36)
            {
                barPattern.Append(fillCharacter, 36 - patternLength);
            }

            else if (fcc == "62" && patternLength < 51)
            {
                barPattern.Append(fillCharacter, 51 - patternLength);
            }

            if (fcc == "11")
            {
                barPattern.Append(fillCharacter);
            }

            AddErrorCorrection(barPattern);

            // Add start & stop characters.
            barPattern.Insert(0, "13");
            barPattern.Append("13");

            SymbolBuilder.BuildFourStateSymbol(Symbol, barPattern);
            barcodeText = new string(barcodeData);
            if (cifLength > 0)
            {
                barcodeText = barcodeText.Insert(10, " ");
            }

            barcodeText = barcodeText.Insert(2, " ");
        }
Ejemplo n.º 2
0
        private void IntellgentMail()
        {
            int       index;
            int       value;
            string    zip      = String.Empty;
            string    tracker  = String.Empty;
            BitVector zipAdder = new BitVector();

            short[] accumulator = new short[112];
            short[] xRegister   = new short[112];
            short[] yRegister   = new short[112];
            byte[]  byteData    = new byte[13];
            uint    uspsCRC;

            int[]         codeword    = new int[10];
            uint[]        characters  = new uint[10];
            int[]         barMap      = new int[130];
            StringBuilder barPattern  = new StringBuilder();
            int           inputLength = barcodeData.Length;

            if (inputLength > 31)
            {
                throw new InvalidDataLengthException("USPS: Input data too long.");
            }

            if (inputLength < 20)
            {
                throw new InvalidDataLengthException("USPS: Invalid tracking code length.");
            }

            // Separate the tracking code from the routing code.
            tracker = new string(barcodeData, 0, 20);
            if (inputLength > 20)
            {
                zip = new string(barcodeData, 20, inputLength - tracker.Length);
            }

            if (zip.Length != 11 && zip.Length != 9 && zip.Length != 5 && zip.Length != 0)
            {
                throw new InvalidDataException("USPS: Invalid ZIP code.");
            }

            Array.Clear(accumulator, 0, 112);
            for (index = 0; index < zip.Length; index++)
            {
                BinaryMath.BinaryMultiply(accumulator, "10");
                BinaryMath.BinaryLoad(xRegister, "0");
                for (int i = 0; i < 4; i++)
                {
                    value = zip[index] - '0';
                    if ((value & (0x01 << i)) > 0)
                    {
                        xRegister[i] = 1;
                    }
                }

                BinaryMath.BinaryAdd(accumulator, xRegister);
            }

            // Add weight to routing code.
            Array.Copy(accumulator, xRegister, 112);
            if (zip.Length > 9)
            {
                zipAdder.AppendBits(545, 10);       // 1000100001
            }
            else
            {
                if (zip.Length > 5)
                {
                    zipAdder.AppendBits(33, 6);     // 100001
                }
                else
                {
                    if (zip.Length > 0)
                    {
                        zipAdder.AppendBit(1);      // 1
                    }
                    else
                    {
                        zipAdder.AppendBit(0);      // 0
                    }
                }
            }

            Array.Clear(accumulator, 0, 112);
            for (index = 0; index < zipAdder.SizeInBits; index++)
            {
                BinaryMath.BinaryMultiply(accumulator, "10");
                BinaryMath.BinaryLoad(yRegister, "0");
                for (int i = 0; i < 4; i++)
                {
                    value = zipAdder[index] - '0';
                    if ((value & (0x01 << i)) > 0)
                    {
                        yRegister[i] = 1;
                    }
                }

                BinaryMath.BinaryAdd(accumulator, yRegister);
            }

            BinaryMath.BinaryAdd(accumulator, xRegister);

            // Tracking code.
            // Multiply by 10.
            BinaryMath.BinaryMultiply(accumulator, "10");
            BinaryMath.BinaryLoad(yRegister, "0");
            for (int i = 0; i < 4; i++)
            {
                value = tracker[0] - '0';
                if ((value & (0x01 << i)) > 0)
                {
                    yRegister[i] = 1;
                }
            }

            BinaryMath.BinaryAdd(accumulator, yRegister);

            // Multiply by 5.
            BinaryMath.BinaryMultiply(accumulator, "5");
            BinaryMath.BinaryLoad(yRegister, "0");
            // Add second digit.
            for (int i = 0; i < 4; i++)
            {
                value = tracker[1] - '0';
                if ((value & (0x01 << i)) > 0)
                {
                    yRegister[i] = 1;
                }
            }

            BinaryMath.BinaryAdd(accumulator, yRegister);

            // And then the rest.
            for (index = 2; index < tracker.Length; index++)
            {
                BinaryMath.BinaryMultiply(accumulator, "10");
                BinaryMath.BinaryLoad(yRegister, "0");
                for (int i = 0; i < 4; i++)
                {
                    value = tracker[index] - '0';
                    if ((value & (0x01 << i)) > 0)
                    {
                        yRegister[i] = 1;
                    }
                }

                BinaryMath.BinaryAdd(accumulator, yRegister);
            }

            // Step 2 - Generation of 11-bit CRC on Binary Data.
            accumulator[103] = 0;
            accumulator[102] = 0;

            for (int i = 0; i < 13; i++)
            {
                int j = 96 - (8 * i);
                byteData[i]  = 0;
                byteData[i] += (byte)accumulator[j];
                byteData[i] += (byte)(2 * accumulator[j + 1]);
                byteData[i] += (byte)(4 * accumulator[j + 2]);
                byteData[i] += (byte)(8 * accumulator[j + 3]);
                byteData[i] += (byte)(16 * accumulator[j + 4]);
                byteData[i] += (byte)(32 * accumulator[j + 5]);
                byteData[i] += (byte)(64 * accumulator[j + 6]);
                byteData[i] += (byte)(128 * accumulator[j + 7]);
            }

            uspsCRC = CRC11GenerateFrameCheckSequence(byteData);

            // Step 3 - Conversion from Binary Data to Codewords.
            // Start with codeword J which is base 636
            Array.Clear(xRegister, 0, 112);
            Array.Clear(yRegister, 0, 112);

            xRegister[101] = 1;
            xRegister[98]  = 1;
            xRegister[97]  = 1;
            xRegister[96]  = 1;
            xRegister[95]  = 1;
            xRegister[94]  = 1;

            for (int i = 92; i >= 0; i--)
            {
                yRegister[i] = BinaryMath.IsLarger(accumulator, xRegister);
                if (yRegister[i] == 1)
                {
                    BinaryMath.BinarySubtract(accumulator, xRegister);
                }

                BinaryMath.ShiftDown(xRegister);
            }

            codeword[9] = (accumulator[9] * 512) + (accumulator[8] * 256) + (accumulator[7] * 128) + (accumulator[6] * 64) +
                          (accumulator[5] * 32) + (accumulator[4] * 16) + (accumulator[3] * 8) + (accumulator[2] * 4) +
                          (accumulator[1] * 2) + accumulator[0];

            // Then codewords I to B with base 1365.
            for (int j = 8; j > 0; j--)
            {
                for (int i = 0; i < 112; i++)
                {
                    accumulator[i] = yRegister[i];
                    yRegister[i]   = 0;
                    xRegister[i]   = 0;
                }

                xRegister[101] = 1;
                xRegister[99]  = 1;
                xRegister[97]  = 1;
                xRegister[95]  = 1;
                xRegister[93]  = 1;
                xRegister[91]  = 1;
                for (int i = 91; i >= 0; i--)
                {
                    yRegister[i] = BinaryMath.IsLarger(accumulator, xRegister);
                    if (yRegister[i] == 1)
                    {
                        BinaryMath.BinarySubtract(accumulator, xRegister);
                    }

                    BinaryMath.ShiftDown(xRegister);
                }

                codeword[j] = (accumulator[10] * 1024) + (accumulator[9] * 512) + (accumulator[8] * 256) +
                              (accumulator[7] * 128) + (accumulator[6] * 64) + (accumulator[5] * 32) +
                              (accumulator[4] * 16) + (accumulator[3] * 8) + (accumulator[2] * 4) +
                              (accumulator[1] * 2) + accumulator[0];
            }

            codeword[0] = (yRegister[10] * 1024) + (yRegister[9] * 512) + (yRegister[8] * 256) +
                          (yRegister[7] * 128) + (yRegister[6] * 64) + (yRegister[5] * 32) +
                          (yRegister[4] * 16) + (yRegister[3] * 8) + (yRegister[2] * 4) +
                          (yRegister[1] * 2) + yRegister[0];

            for (int i = 0; i < 8; i++)
            {
                if (codeword[i] == 1365)
                {
                    codeword[i] = 0;
                    codeword[i + 1]++;
                }
            }

            // Step 4 - Inserting Additional Information into Codewords.
            codeword[9] = codeword[9] * 2;
            if (uspsCRC >= 1024)
            {
                codeword[0] += 659;
            }

            // Step 5 - Conversion from Codewords to Characters.
            for (int i = 0; i < 10; i++)
            {
                if (codeword[i] < 1287)
                {
                    characters[i] = AppendixD1[codeword[i]];
                }

                else
                {
                    characters[i] = AppendixD2[codeword[i] - 1287];
                }
            }

            for (int i = 0; i < 10; i++)
            {
                if ((uspsCRC & (1 << i)) > 0)
                {
                    characters[i] = 0x1FFF - characters[i];
                }
            }

            // Step 6 - Conversion from Characters to the Intelligent Mail Barcode.
            for (int i = 0; i < 10; i++)
            {
                for (int j = 0; j < 13; j++)
                {
                    if ((characters[i] & (1 << j)) > 0)
                    {
                        barMap[AppendixD4[(13 * i) + j] - 1] = 1;
                    }

                    else
                    {
                        barMap[AppendixD4[(13 * i) + j] - 1] = 0;
                    }
                }
            }

            for (int i = 0; i < 65; i++)
            {
                int j = 0;
                if (barMap[i] == 0)
                {
                    j += 1;
                }

                if (barMap[i + 65] == 0)
                {
                    j += 2;
                }

                barPattern.Append(j);
            }

            SymbolBuilder.BuildFourStateSymbol(Symbol, barPattern);
            // Format the barcodes text.
            barcodeText = new string(barcodeData);
            if (zip.Length > 0)
            {
                if (zip.Length == 11)
                {
                    barcodeText = barcodeText.Insert(29, " ");
                }

                if (zip.Length >= 9)
                {
                    barcodeText = barcodeText.Insert(25, " ");
                }

                if (zip.Length >= 5)
                {
                    barcodeText = barcodeText.Insert(20, " ");
                }
            }

            if (tracker[5] < '9')
            {
                barcodeText = barcodeText.Insert(11, " ");
            }

            else
            {
                barcodeText = barcodeText.Insert(14, " ");
            }

            barcodeText = barcodeText.Insert(5, " ");
            barcodeText = barcodeText.Insert(2, " ");
        }
Ejemplo n.º 3
0
        private void Mailmark()
        {
            int    inputLength   = barcodeData.Length;
            char   barcodeType   = 'C';
            int    formatId      = 0;
            int    versionId     = 0;
            int    classId       = 0;
            int    supplyChainId = 0;
            int    itemId        = 0;
            string postcode      = String.Empty;
            int    postcodeType  = 0;
            string pattern       = String.Empty;

            short[] destinationPostcode = new short[112];
            short[] aRegister           = new short[112];
            short[] bRegister           = new short[112];
            short[] tempRegister        = new short[112];
            short[] cdvRegister         = new short[112];
            byte[]  data = new byte[26];
            int     dataTop, dataStep;

            byte[]        check    = new byte[7];
            short[]       extender = new short[27];
            int           checkCount;
            StringBuilder barPattern = new StringBuilder();
            bool          result;

            if (inputLength > 26)
            {
                throw new InvalidDataLengthException("Mailmark: Input data too long.");
            }

            if (inputLength <= 22)
            {
                for (int i = inputLength; i < 22; i++)
                {
                    barcodeData = ArrayEx.ArrayExtensions.Insert(barcodeData, inputLength, ' ');
                }

                inputLength = barcodeData.Length;
                barcodeType = 'C';
            }


            if (inputLength > 22 && inputLength <= 26)
            {
                for (int i = inputLength; i < 26; i++)
                {
                    barcodeData = ArrayEx.ArrayExtensions.Insert(barcodeData, inputLength, ' ');
                }

                inputLength = barcodeData.Length;
                barcodeType = 'L';
            }

            for (int i = 0; i < inputLength; i++)
            {
                barcodeData[i] = Char.ToUpper(barcodeData[i], CultureInfo.CurrentCulture);  // Make sure all characters are uppercase.
                if (CharacterSets.Mailmark.IndexOf(barcodeData[i]) == -1)
                {
                    throw new InvalidDataException("Mailmark: Invalid character in input data.");
                }
            }

            // Format is in the range 0-4.
            result = int.TryParse((new string(barcodeData, 0, 1)), out formatId);
            if (!result || formatId < 0 || formatId > 4)
            {
                throw new InvalidDataException("Mailmark: Invalid Format character in input data.");
            }

            // Version ID is in the range 1-4.
            result = int.TryParse((new string(barcodeData, 1, 1)), out versionId);
            versionId--;    // Internal field value of 0-3.
            if (!result || versionId < 0 || versionId > 3)
            {
                throw new InvalidDataException("Mailmark: Invalid Version ID character in input data.");
            }

            // Class is in the range 0-9 & A-E.
            result = int.TryParse((new string(barcodeData, 2, 1)), NumberStyles.HexNumber, null, out classId);
            if (!result || classId < 0 || classId > 14)
            {
                throw new InvalidDataException("Mailmark: Invalid Class ID character in input data.");
            }

            // Supply Chain ID is 2 digits for barcode C and 6 digits for barcode L
            int supplyChainLength = (barcodeType == 'C') ? 2 : 6;

            result = int.TryParse(new string(barcodeData, 3, supplyChainLength), out supplyChainId);
            if (!result)
            {
                throw new InvalidDataException("Mailmark: Invalid Supply Chain ID character in input data.");
            }

            // Item ID is 8 digits.
            result = int.TryParse(new string(barcodeData, 3 + supplyChainLength, 8), out itemId);
            if (!result)
            {
                throw new InvalidDataException("Mailmark: Invalid Item ID character in input data.");
            }

            // Seperate Destination Post Code plus DPS field.
            postcode = new string(barcodeData, 3 + supplyChainLength + 8, 9);

            // Detect postcode type.

            /* Postcode type is used to select which format of postcode
             *
             * 1 = FNFNLLNLS
             * 2 = FFNNLLNLS
             * 3 = FFNNNLLNL
             * 4 = FFNFNLLNL
             * 5 = FNNLLNLSS
             * 6 = FNNNLLNLS
             * 7 = International designation*/

            if (postcode == "XY11     ")
            {
                postcodeType = 7;
            }

            else
            {
                if (postcode[7] == ' ')
                {
                    postcodeType = 5;
                }

                else
                {
                    if (postcode[8] == ' ')
                    {
                        // Types 1, 2 and 6.
                        if (Char.IsDigit(postcode[1]))
                        {
                            if (Char.IsDigit(postcode[2]))
                            {
                                postcodeType = 6;
                            }

                            else
                            {
                                postcodeType = 1;
                            }
                        }

                        else
                        {
                            postcodeType = 2;
                        }
                    }

                    else
                    {
                        // Types 3 and 4.
                        if (Char.IsDigit(postcode[3]))
                        {
                            postcodeType = 3;
                        }

                        else
                        {
                            postcodeType = 4;
                        }
                    }
                }
            }

            // Verify postcode type.
            if (postcodeType != 7)
            {
                if (!VerifyPostcode(postcode, postcodeType))
                {
                    throw new InvalidDataException("Mailmark: Invalid Postcode in input data.");
                }
            }

            // Convert postcode to internal user field.
            if (postcodeType != 7)
            {
                pattern = postcodeFormat[postcodeType - 1];
                BinaryMath.BinaryLoad(bRegister, "0");
                for (int i = 0; i < 9; i++)
                {
                    switch (pattern[i])
                    {
                    case 'F':
                        BinaryMath.BinaryMultiply(bRegister, "26");
                        BinaryMath.BinaryLoad(tempRegister, "0");
                        for (int j = 0; j < 5; j++)
                        {
                            if ((SetF.IndexOf(postcode[i]) & (0x01 << j)) > 0)
                            {
                                tempRegister[j] = 1;
                            }
                        }

                        BinaryMath.BinaryAdd(bRegister, tempRegister);
                        break;

                    case 'L':
                        BinaryMath.BinaryMultiply(bRegister, "20");
                        BinaryMath.BinaryLoad(tempRegister, "0");
                        for (int j = 0; j < 5; j++)
                        {
                            if ((SetL.IndexOf(postcode[i]) & (0x01 << j)) > 0)
                            {
                                tempRegister[j] = 1;
                            }
                        }

                        BinaryMath.BinaryAdd(bRegister, tempRegister);
                        break;

                    case 'N':
                        BinaryMath.BinaryMultiply(bRegister, "10");
                        BinaryMath.BinaryLoad(tempRegister, "0");
                        for (int j = 0; j < 5; j++)
                        {
                            if ((SetN.IndexOf(postcode[i]) & (0x01 << j)) > 0)
                            {
                                tempRegister[j] = 1;
                            }
                        }

                        BinaryMath.BinaryAdd(bRegister, tempRegister);
                        break;
                    }
                }

                // Destination postcode = accumulatorA + accumulatorB.
                BinaryMath.BinaryLoad(destinationPostcode, "0");
                BinaryMath.BinaryAdd(destinationPostcode, bRegister);

                BinaryMath.BinaryLoad(aRegister, "1");
                if (postcodeType == 1)
                {
                    BinaryMath.BinaryAdd(destinationPostcode, aRegister);
                }

                BinaryMath.BinaryLoad(tempRegister, "5408000000");
                BinaryMath.BinaryAdd(aRegister, tempRegister);

                if (postcodeType == 2)
                {
                    BinaryMath.BinaryAdd(destinationPostcode, aRegister);
                }

                BinaryMath.BinaryLoad(tempRegister, "5408000000");
                BinaryMath.BinaryAdd(aRegister, tempRegister);

                if (postcodeType == 3)
                {
                    BinaryMath.BinaryAdd(destinationPostcode, aRegister);
                }

                BinaryMath.BinaryLoad(tempRegister, "54080000000");
                BinaryMath.BinaryAdd(aRegister, tempRegister);

                if (postcodeType == 4)
                {
                    BinaryMath.BinaryAdd(destinationPostcode, aRegister);
                }

                BinaryMath.BinaryLoad(tempRegister, "140608000000");
                BinaryMath.BinaryAdd(aRegister, tempRegister);

                if (postcodeType == 5)
                {
                    BinaryMath.BinaryAdd(destinationPostcode, aRegister);
                }

                BinaryMath.BinaryLoad(tempRegister, "208000000");
                BinaryMath.BinaryAdd(aRegister, tempRegister);

                if (postcodeType == 6)
                {
                    BinaryMath.BinaryAdd(destinationPostcode, aRegister);
                }
            }

            // Conversion from Internal User Fields to Consolidated Data Value
            // Set CDV to 0
            BinaryMath.BinaryLoad(cdvRegister, "0");

            // Add Destination Post Code plus DPS
            BinaryMath.BinaryAdd(cdvRegister, destinationPostcode);

            // Multiply by 100,000,000
            BinaryMath.BinaryMultiply(cdvRegister, "100000000");

            // Add Item ID
            BinaryMath.BinaryLoad(tempRegister, "0");
            for (int i = 0; i < 26; i++)
            {
                if ((0x01 & (itemId >> i)) > 0)
                {
                    tempRegister[i] = 1;
                }
            }

            BinaryMath.BinaryAdd(cdvRegister, tempRegister);

            if (barcodeType == 'C')
            {
                BinaryMath.BinaryMultiply(cdvRegister, "100");  // Barcode C - Multiply by 100
            }
            else
            {
                BinaryMath.BinaryMultiply(cdvRegister, "1000000");  // Barcode L - Multiply by 1,000,000
            }
            // Add supply chain id.
            BinaryMath.BinaryLoad(tempRegister, "0");
            for (int i = 0; i < 20; i++)
            {
                if ((0x01 & (supplyChainId >> i)) > 0)
                {
                    tempRegister[i] = 1;
                }
            }

            BinaryMath.BinaryAdd(cdvRegister, tempRegister);

            // Multiply by 15.
            BinaryMath.BinaryMultiply(cdvRegister, "15");

            // Add class.
            BinaryMath.BinaryLoad(tempRegister, "0");
            for (int i = 0; i < 4; i++)
            {
                if ((0x01 & (classId >> i)) > 0)
                {
                    tempRegister[i] = 1;
                }
            }

            BinaryMath.BinaryAdd(cdvRegister, tempRegister);
            // Multiply by 5.
            BinaryMath.BinaryMultiply(cdvRegister, "5");

            // Add format.
            BinaryMath.BinaryLoad(tempRegister, "0");
            for (int i = 0; i < 4; i++)
            {
                if ((0x01 & (formatId >> i)) > 0)
                {
                    tempRegister[i] = 1;
                }
            }

            BinaryMath.BinaryAdd(cdvRegister, tempRegister);

            // Multiply by 4.
            BinaryMath.BinaryMultiply(cdvRegister, "4");
            // Add version id.
            BinaryMath.BinaryLoad(tempRegister, "0");
            for (int i = 0; i < 4; i++)
            {
                if ((0x01 & (versionId >> i)) > 0)
                {
                    tempRegister[i] = 1;
                }
            }

            BinaryMath.BinaryAdd(cdvRegister, tempRegister);
            if (barcodeType == 'C')
            {
                dataTop    = 15;
                dataStep   = 8;
                checkCount = 6;
            }

            else
            {
                dataTop    = 18;
                dataStep   = 10;
                checkCount = 7;
            }

            // Conversion from consolidated data value to data numbers.
            for (int i = 0; i < 112; i++)
            {
                bRegister[i] = cdvRegister[i];
            }

            for (int j = dataTop; j >= (dataStep + 1); j--)
            {
                for (int i = 0; i < 112; i++)
                {
                    cdvRegister[i] = bRegister[i];
                    bRegister[i]   = 0;
                    aRegister[i]   = 0;
                }

                aRegister[96] = 1;
                for (int i = 91; i >= 0; i--)
                {
                    bRegister[i] = BinaryMath.IsLarger(cdvRegister, aRegister);
                    if (bRegister[i] == 1)
                    {
                        BinaryMath.BinarySubtract(cdvRegister, aRegister);
                    }

                    BinaryMath.ShiftDown(aRegister);
                }

                data[j] = (byte)((cdvRegister[5] * 32) + (cdvRegister[4] * 16) + (cdvRegister[3] * 8) + (cdvRegister[2] * 4) + (cdvRegister[1] * 2) + cdvRegister[0]);
            }

            for (int j = dataStep; j >= 0; j--)
            {
                for (int i = 0; i < 112; i++)
                {
                    cdvRegister[i] = bRegister[i];
                    bRegister[i]   = 0;
                    aRegister[i]   = 0;
                }

                aRegister[95] = 1;
                aRegister[94] = 1;
                aRegister[93] = 1;
                aRegister[92] = 1;
                for (int i = 91; i >= 0; i--)
                {
                    bRegister[i] = BinaryMath.IsLarger(cdvRegister, aRegister);
                    if (bRegister[i] == 1)
                    {
                        BinaryMath.BinarySubtract(cdvRegister, aRegister);
                    }

                    BinaryMath.ShiftDown(aRegister);
                }

                data[j] = (byte)((cdvRegister[5] * 32) + (cdvRegister[4] * 16) + (cdvRegister[3] * 8) + (cdvRegister[2] * 4) + (cdvRegister[1] * 2) + cdvRegister[0]);
            }

            ReedSolomon.RSInitialise(0x25, checkCount, 1);
            ReedSolomon.RSEncode(dataTop + 1, data, check);

            // Append check digits to data.
            for (int i = 1; i <= checkCount; i++)
            {
                data[dataTop + i] = check[checkCount - i];
            }

            // Conversion from data numbers and check numbers to data symbols and check symbols.
            for (int i = 0; i <= dataStep; i++)
            {
                data[i] = dataSymbolEven[data[i]];
            }

            for (int i = dataStep + 1; i <= (dataTop + checkCount); i++)
            {
                data[i] = dataSymbolOdd[data[i]];
            }

            // Conversion from data symbols and check symbols to extender groups.
            for (int i = 0; i < inputLength; i++)
            {
                if (barcodeType == 'C')
                {
                    extender[extenderGroupC[i]] = data[i];
                }

                else
                {
                    extender[extenderGroupL[i]] = data[i];
                }
            }

            // Conversion from extender groups to bar identifiers.
            for (int i = 0; i < inputLength; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    switch (extender[i] & 0x24)
                    {
                    case 0x24:
                        barPattern.Append("F");
                        break;

                    case 0x20:
                        if (i % 2 > 0)
                        {
                            barPattern.Append("D");
                        }

                        else
                        {
                            barPattern.Append("A");
                        }

                        break;

                    case 0x04:
                        if (i % 2 > 0)
                        {
                            barPattern.Append("A");
                        }

                        else
                        {
                            barPattern.Append("D");
                        }

                        break;

                    default:
                        barPattern.Append("T");
                        break;
                    }

                    extender[i] = (short)(extender[i] << 1);
                }
            }

            SymbolBuilder.BuildFourStateSymbol(Symbol, barPattern);
            barcodeText = new string(barcodeData);
        }