// Path: src/main/java/uk/org/okapibarcode/backend/DataBarLimited.java
// static int[] getWidths(int val, int n, int elements, int maxWidth, int noNarrow) {
// 
//     int bar;
//     int elmWidth;
//     int mxwElement;
//     int subVal, lessVal;
//     int narrowMask = 0;
//     int[] widths = new int[elements];
// 
//     for (bar = 0; bar < elements - 1; bar++) {
//         for (elmWidth = 1, narrowMask |= (1 << bar); ;
//                 elmWidth++, narrowMask &= ~ (1 << bar)) {
//             /* get all combinations */
//             subVal = getCombinations(n - elmWidth - 1, elements - bar - 2);
//             /* less combinations with no single-module element */
//             if ((noNarrow == 0) && (narrowMask == 0)
//                     && (n - elmWidth - (elements - bar - 1) >= elements - bar - 1)) {
//                 subVal -= getCombinations(n - elmWidth - (elements - bar), elements - bar - 2);
//             }
//             /* less combinations with elements > maxVal */
//             if (elements - bar - 1 > 1) {
//                 lessVal = 0;
//                 for (mxwElement = n - elmWidth - (elements - bar - 2);
//                 mxwElement > maxWidth;
//                 mxwElement--) {
//                     lessVal += getCombinations(n - elmWidth - mxwElement - 1, elements - bar - 3);
//                 }
//                 subVal -= lessVal * (elements - 1 - bar);
//             } else if (n - elmWidth > maxWidth) {
//                 subVal--;
//             }
//             val -= subVal;
//             if (val < 0) break;
//         }
//         val += subVal;
//         n -= elmWidth;
//         widths[bar] = elmWidth;
//     }
// 
//     widths[bar] = n;
// 
//     return widths;
// }
// 
// Path: src/main/java/uk/org/okapibarcode/util/Strings.java
// public static void binaryAppend(StringBuilder s, int value, int digits) {
//     int start = 0x01 << (digits - 1);
//     for (int i = 0; i < digits; i++) {
//         if ((value & (start >> i)) == 0) {
//             s.append('0');
//         } else {
//             s.append('1');
//         }
//     }
// }


import static uk.org.okapibarcode.backend.DataBarLimited.getWidths;
import static uk.org.okapibarcode.util.Strings.binaryAppend;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.concurrent.atomic.AtomicBoolean;
                    if (generalField[i] == ',') binaryString.append("11110001"); /* comma */
                    if (generalField[i] == '-') binaryString.append("11110010"); /* minus or hyphen */
                    if (generalField[i] == '.') binaryString.append("11110011"); /* period or full stop */
                    if (generalField[i] == '/') binaryString.append("11110100"); /* slash or solidus */
                    if (generalField[i] == ':') binaryString.append("11110101"); /* colon */
                    if (generalField[i] == ';') binaryString.append("11110110"); /* semicolon */
                    if (generalField[i] == '<') binaryString.append("11110111"); /* less-than sign */
                    if (generalField[i] == '=') binaryString.append("11111000"); /* equals sign */
                    if (generalField[i] == '>') binaryString.append("11111001"); /* greater-than sign */
                    if (generalField[i] == '?') binaryString.append("11111010"); /* question mark */
                    if (generalField[i] == '_') binaryString.append("11111011"); /* underline or low line */
                    if (generalField[i] == ' ') binaryString.append("11111100"); /* space */
                    i++;
                    break;
                }

                current_length = i;
                if (latch) {
                    current_length++;
                }
            }

            remainder = calculateRemainder(binaryString.length(), stacked, blocksPerRow);

            if (latch) {
                /* There is still one more numeric digit to encode */
                if (last_mode == EncodeMode.NUMERIC) {
                    if (remainder >= 4 && remainder <= 6) {
                        value = generalField[i] - '0';
                        value++;
// Path: src/main/java/uk/org/okapibarcode/backend/DataBarLimited.java
// static int[] getWidths(int val, int n, int elements, int maxWidth, int noNarrow) {
// 
//     int bar;
//     int elmWidth;
//     int mxwElement;
//     int subVal, lessVal;
//     int narrowMask = 0;
//     int[] widths = new int[elements];
// 
//     for (bar = 0; bar < elements - 1; bar++) {
//         for (elmWidth = 1, narrowMask |= (1 << bar); ;
//                 elmWidth++, narrowMask &= ~ (1 << bar)) {
//             /* get all combinations */
//             subVal = getCombinations(n - elmWidth - 1, elements - bar - 2);
//             /* less combinations with no single-module element */
//             if ((noNarrow == 0) && (narrowMask == 0)
//                     && (n - elmWidth - (elements - bar - 1) >= elements - bar - 1)) {
//                 subVal -= getCombinations(n - elmWidth - (elements - bar), elements - bar - 2);
//             }
//             /* less combinations with elements > maxVal */
//             if (elements - bar - 1 > 1) {
//                 lessVal = 0;
//                 for (mxwElement = n - elmWidth - (elements - bar - 2);
//                 mxwElement > maxWidth;
//                 mxwElement--) {
//                     lessVal += getCombinations(n - elmWidth - mxwElement - 1, elements - bar - 3);
//                 }
//                 subVal -= lessVal * (elements - 1 - bar);
//             } else if (n - elmWidth > maxWidth) {
//                 subVal--;
//             }
//             val -= subVal;
//             if (val < 0) break;
//         }
//         val += subVal;
//         n -= elmWidth;
//         widths[bar] = elmWidth;
//     }
// 
//     widths[bar] = n;
// 
//     return widths;
// }
// 
// Path: src/main/java/uk/org/okapibarcode/util/Strings.java
// public static void binaryAppend(StringBuilder s, int value, int digits) {
//     int start = 0x01 << (digits - 1);
//     for (int i = 0; i < digits; i++) {
//         if ((value & (start >> i)) == 0) {
//             s.append('0');
//         } else {
//             s.append('1');
//         }
//     }
// }


// Path: src/main/java/uk/org/okapibarcode/backend/DataBarExpanded.java
import static uk.org.okapibarcode.backend.DataBarLimited.getWidths;
import static uk.org.okapibarcode.util.Strings.binaryAppend;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.concurrent.atomic.AtomicBoolean;

                    if (generalField[i] == ',') binaryString.append("11110001"); /* comma */
                    if (generalField[i] == '-') binaryString.append("11110010"); /* minus or hyphen */
                    if (generalField[i] == '.') binaryString.append("11110011"); /* period or full stop */
                    if (generalField[i] == '/') binaryString.append("11110100"); /* slash or solidus */
                    if (generalField[i] == ':') binaryString.append("11110101"); /* colon */
                    if (generalField[i] == ';') binaryString.append("11110110"); /* semicolon */
                    if (generalField[i] == '<') binaryString.append("11110111"); /* less-than sign */
                    if (generalField[i] == '=') binaryString.append("11111000"); /* equals sign */
                    if (generalField[i] == '>') binaryString.append("11111001"); /* greater-than sign */
                    if (generalField[i] == '?') binaryString.append("11111010"); /* question mark */
                    if (generalField[i] == '_') binaryString.append("11111011"); /* underline or low line */
                    if (generalField[i] == ' ') binaryString.append("11111100"); /* space */
                    i++;
                    break;
                }

                current_length = i;
                if (latch) {
                    current_length++;
                }
            }

            remainder = calculateRemainder(binaryString.length(), stacked, blocksPerRow);

            if (latch) {
                /* There is still one more numeric digit to encode */
                if (last_mode == EncodeMode.NUMERIC) {
                    if (remainder >= 4 && remainder <= 6) {
                        value = generalField[i] - '0';
                        value++;
                        binaryAppend(binaryString, value, 4);