{"id":230,"date":"2026-03-04T15:28:43","date_gmt":"2026-03-04T15:28:43","guid":{"rendered":"https:\/\/primetoolhub.com\/?page_id=230"},"modified":"2026-07-04T05:11:38","modified_gmt":"2026-07-04T05:11:38","slug":"universal-logic-gate-converter-pro","status":"publish","type":"page","link":"https:\/\/schoolict.net\/tools\/universal-logic-gate-converter-pro\/","title":{"rendered":"Universal Logic Gate Converter Pro | Boolean to NAND\/NOR"},"content":{"rendered":"\n<div class=\"pth-hero-section\">\n    <div class=\"pth-hero-content\">\n        <h2>Universal Logic Gate Converter Pro | Boolean to NAND\/NOR<\/h2>\n        <p>100% offline Advanced Universal Gate Converter. Simplify Boolean expressions step-by-step, convert to raw and optimized NAND\/NOR gates, and generate synthesizable Verilog code instantly.<\/p>\n\n        <div id=\"pth-toc-placeholder\"><\/div>\n    <\/div>\n\n<div class=\"pth-hero-image\">\n    <img data-no-lazy=\"1\"\n         src=\"https:\/\/schoolict.net\/tools\/wp-content\/uploads\/2026\/03\/Universal-Logic-Gate-Converter-Pro-800x447.jpeg\"\n         width=\"800\"\n         height=\"447\"\n         alt=\"Universal Gate Converter\"\n         fetchpriority=\"high\"\n         loading=\"eager\"\n         decoding=\"async\"\n         style=\"width:100%; height:auto; display:block;\">\n  <\/div>\n<\/div>\n\n\n\n\n<div class=\"wp-block-rank-math-toc-block\" id=\"rank-math-toc\"><h2>Table of Contents<\/h2><nav><ul><li><a href=\"#\ud83d\udd34-how-a-boolean-to-nand-nor-converter-actually-works\">\ud83d\udd34 How a Boolean to NAND\/NOR Converter Actually Works<\/a><ul><li><a href=\"#\ud83d\udfe2-the-ast-parser-and-full-operator-support\">\ud83d\udfe2 The AST Parser and Full Operator Support<\/a><\/li><\/ul><\/li><li><a href=\"#\ud83d\udfe1-truth-tables-karnaugh-maps-and-gate-count-analysis\">\ud83d\udfe1 Truth Tables, Karnaugh Maps, and Gate Count Analysis<\/a><ul><li><a href=\"#\ud83d\udfe2-gate-count-comparison-nand-vs-nor\">\ud83d\udfe2 Gate Count Comparison \u2014 NAND vs NOR<\/a><\/li><\/ul><\/li><li><a href=\"#\ud83d\udd34-vhdl-export-verilog-simulation-and-session-history\">\ud83d\udd34 VHDL Export, Verilog Simulation, and Session History<\/a><\/li><\/ul><\/nav><\/div>\n\n\n<style>\r\n\/* ============================================================\r\n   PTH UNIVERSAL LOGIC GATE CONVERTER PRO \u2014 v3.0\r\n   AdSense + PageSpeed + WCAG 2.1 AA Compliant\r\n   All features: Truth Table, K-Map, Gate Count, VHDL,\r\n   History Panel, XNOR\/XOR fix, v2.0 compliance\r\n   ============================================================ *\/\r\n#pth-logic-gate-wrapper {\r\n    font-family: 'Inter', system-ui, sans-serif;\r\n    width: 100%; max-width: 1400px; margin: 0 auto;\r\n    box-sizing: border-box; background: #f8fafc;\r\n    padding: 20px; border-radius: 16px;\r\n    color: #1e293b; font-weight: 500;\r\n}\r\n#pth-logic-gate-wrapper * { box-sizing: border-box; min-width: 0; }\r\n#pth-logic-gate-wrapper h2,\r\n#pth-logic-gate-wrapper h3,\r\n#pth-logic-gate-wrapper h4 { color: #0f172a; font-weight: 800; margin-top: 0; }\r\n\r\n#pth-logic-gate-wrapper .pth-tool-title {\r\n    font-size: 26px; font-weight: 800; color: #1d4ed8; margin: 0;\r\n}\r\n\r\n\/* Cards *\/\r\n#pth-logic-gate-wrapper .pth-card {\r\n    background: #ffffff; border: 1px solid #e2e8f0;\r\n    border-radius: 12px; padding: 25px; margin-bottom: 20px;\r\n    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05);\r\n}\r\n\r\n\/* Tool meta bar *\/\r\n#pth-logic-gate-wrapper .pth-tool-meta-bar {\r\n    display: flex; align-items: center; gap: 10px;\r\n    flex-wrap: wrap; margin-bottom: 15px;\r\n}\r\n#pth-logic-gate-wrapper .pth-version-badge {\r\n    background: #eff6ff; color: #1d4ed8; border: 1px solid #bfdbfe;\r\n    font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 4px;\r\n}\r\n#pth-logic-gate-wrapper .pth-status-offline {\r\n    background: #f0fdf4; color: #15803d; border: 1px solid #bbf7d0;\r\n    font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 4px;\r\n}\r\n\/* pth-guide-link removed v3.1 *\/\r\n\r\n\/* Layout *\/\r\n#pth-logic-gate-wrapper .pth-flex-layout {\r\n    display: grid; grid-template-columns: 1.8fr 1fr;\r\n    gap: 24px; align-items: start;\r\n}\r\n#pth-logic-gate-wrapper .pth-flex-layout.pth-full-width {\r\n    grid-template-columns: 100%;\r\n}\r\n\r\n\/* Buttons *\/\r\n#pth-logic-gate-wrapper .pth-btn {\r\n    padding: 10px 20px; border-radius: 8px; font-weight: 700;\r\n    cursor: pointer; border: none; font-family: 'Inter', sans-serif;\r\n    font-size: 13px; transition: 0.2s; display: inline-flex;\r\n    align-items: center; justify-content: center; gap: 6px;\r\n}\r\n#pth-logic-gate-wrapper .pth-btn-primary { background: #2563eb; color: #fff; }\r\n#pth-logic-gate-wrapper .pth-btn-primary:hover { background: #1d4ed8; }\r\n#pth-logic-gate-wrapper .pth-btn-secondary {\r\n    background: #f1f5f9; color: #0f172a; border: 1px solid #e2e8f0;\r\n}\r\n#pth-logic-gate-wrapper .pth-btn-secondary:hover { background: #e2e8f0; }\r\n#pth-logic-gate-wrapper .pth-btn-success { background: #059669; color: #fff; }\r\n#pth-logic-gate-wrapper .pth-btn-success:hover { background: #047857; }\r\n#pth-logic-gate-wrapper .pth-btn-danger {\r\n    background: #fef2f2; color: #991b1b; border: 1px solid #fecaca;\r\n}\r\n#pth-logic-gate-wrapper .pth-btn-danger:hover { background: #fee2e2; }\r\n#pth-logic-gate-wrapper .pth-btn-purple {\r\n    background: #faf5ff; color: #5b21b6; border: 1px solid #e9d5ff;\r\n}\r\n#pth-logic-gate-wrapper .pth-btn-purple:hover { background: #ede9fe; }\r\n#pth-logic-gate-wrapper .pth-btn-orange {\r\n    background: #fff7ed; color: #c2410c; border: 1px solid #fed7aa;\r\n}\r\n#pth-logic-gate-wrapper .pth-btn-orange:hover { background: #ffedd5; }\r\n\r\n#pth-logic-gate-wrapper .pth-sample-btn {\r\n    background: #d1fae5; color: #047857; border: 1px solid #10b981;\r\n    font-size: 0.75rem; padding: 4px 10px; border-radius: 6px;\r\n    font-weight: 700; cursor: pointer; transition: 0.2s;\r\n    display: inline-flex; align-items: center; gap: 4px;\r\n}\r\n#pth-logic-gate-wrapper .pth-sample-btn:hover { background: #a7f3d0; }\r\n\r\n\/* Input group *\/\r\n#pth-logic-gate-wrapper .pth-input-group { margin-bottom: 16px; }\r\n#pth-logic-gate-wrapper label {\r\n    font-weight: 700; color: #0f172a; margin-bottom: 6px; display: block;\r\n    font-size: 13px; text-transform: uppercase; letter-spacing: 0.4px;\r\n}\r\n#pth-logic-gate-wrapper input,\r\n#pth-logic-gate-wrapper select,\r\n#pth-logic-gate-wrapper textarea {\r\n    width: 100%; padding: 10px 14px; border: 2px solid #e2e8f0;\r\n    border-radius: 8px; font-family: 'Courier New', monospace;\r\n    font-size: 16px; font-weight: 700; color: #0f172a;\r\n    background: #ffffff; transition: 0.2s;\r\n}\r\n#pth-logic-gate-wrapper input:focus,\r\n#pth-logic-gate-wrapper textarea:focus {\r\n    border-color: #3b82f6; outline: none;\r\n    box-shadow: 0 0 0 3px rgba(59,130,246,0.1);\r\n}\r\n#pth-logic-gate-wrapper input[readonly] {\r\n    background: #f8fafc; color: #334155; font-size: 14px;\r\n}\r\n\r\n\/* Button group *\/\r\n#pth-logic-gate-wrapper .pth-btn-group {\r\n    display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px;\r\n}\r\n\r\n\/* Error box *\/\r\n#pth-logic-gate-wrapper .pth-error-box {\r\n    display: none; background: #fef2f2; border-left: 4px solid #ef4444;\r\n    color: #b91c1c; padding: 14px; margin-bottom: 16px;\r\n    border-radius: 8px; font-weight: 700; font-size: 14px;\r\n}\r\n\r\n\/* Section header *\/\r\n#pth-logic-gate-wrapper .pth-section-header {\r\n    font-size: 16px; font-weight: 800; color: #0f172a;\r\n    margin: 0 0 14px 0; padding-bottom: 10px;\r\n    border-bottom: 2px solid #e2e8f0;\r\n    display: flex; justify-content: space-between; align-items: center;\r\n}\r\n\r\n\/* Formula box *\/\r\n#pth-logic-gate-wrapper .pth-formula-box {\r\n    font-family: 'Courier New', monospace; background: #f8fafc;\r\n    padding: 14px; border-radius: 8px; border-left: 5px solid #2563eb;\r\n    font-weight: 800; color: #1e293b; margin: 10px 0;\r\n    word-break: break-word; white-space: pre-wrap; font-size: 14px;\r\n    min-height: 48px;\r\n}\r\n#pth-logic-gate-wrapper .pth-nand-accent { border-left-color: #8b5cf6; }\r\n#pth-logic-gate-wrapper .pth-nor-accent { border-left-color: #ea580c; }\r\n#pth-logic-gate-wrapper .pth-vhdl-accent { border-left-color: #0891b2; }\r\n#pth-logic-gate-wrapper .pth-nand-text { color: #5b21b6; }\r\n#pth-logic-gate-wrapper .pth-nor-text { color: #c2410c; }\r\n\r\n\/* Code block *\/\r\n#pth-logic-gate-wrapper .pth-code-pre {\r\n    background: #0f172a; color: #4ade80; padding: 16px; border-radius: 8px;\r\n    font-size: 12px; overflow-x: auto; margin-top: 10px;\r\n    font-family: 'Courier New', monospace; white-space: pre-wrap;\r\n    border: 1px solid #1e293b; display: none;\r\n}\r\n\r\n\/* Steps container *\/\r\n#pth-logic-gate-wrapper .pth-steps-container {\r\n    background: #fffbeb; border: 1px solid #fde68a;\r\n    padding: 16px; border-radius: 8px; min-height: 60px;\r\n}\r\n#pth-logic-gate-wrapper .pth-step-row {\r\n    margin-bottom: 10px; padding-bottom: 10px;\r\n    border-bottom: 1px dashed #fcd34d; font-size: 13px;\r\n}\r\n#pth-logic-gate-wrapper .pth-step-row:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }\r\n#pth-logic-gate-wrapper .pth-step-logic {\r\n    font-family: 'Courier New', monospace; font-size: 13px;\r\n    display: block; margin-top: 4px; color: #92400e;\r\n}\r\n\r\n\/* Output area \u2014 prevents CLS *\/\r\n#pth-logic-gate-wrapper .pth-output-area { min-height: 120px; }\r\n\r\n\/* Simplified display *\/\r\n#pth-logic-gate-wrapper .pth-simplified-display {\r\n    font-family: 'Courier New', monospace; font-size: 18px;\r\n    font-weight: 800; color: #16a34a; margin-top: 6px; min-height: 28px;\r\n}\r\n\r\n\/* Action bar *\/\r\n#pth-logic-gate-wrapper .pth-action-bar {\r\n    display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap;\r\n}\r\n\r\n\/* ===== TRUTH TABLE ===== *\/\r\n#pth-logic-gate-wrapper .pth-truth-table-wrap {\r\n    overflow-x: auto; min-height: 80px;\r\n}\r\n#pth-logic-gate-wrapper .pth-truth-table {\r\n    width: 100%; border-collapse: collapse; font-size: 13px;\r\n    font-family: 'Courier New', monospace;\r\n}\r\n#pth-logic-gate-wrapper .pth-truth-table th {\r\n    background: #1e293b; color: #fff; padding: 8px 14px;\r\n    text-align: center; font-weight: 800; letter-spacing: 0.5px;\r\n}\r\n#pth-logic-gate-wrapper .pth-truth-table td {\r\n    padding: 7px 14px; text-align: center;\r\n    border-bottom: 1px solid #f1f5f9; font-weight: 700;\r\n}\r\n#pth-logic-gate-wrapper .pth-truth-table tr:nth-child(even) td { background: #f8fafc; }\r\n#pth-logic-gate-wrapper .pth-truth-table .pth-out-1 { color: #059669; font-weight: 800; }\r\n#pth-logic-gate-wrapper .pth-truth-table .pth-out-0 { color: #991b1b; font-weight: 800; }\r\n#pth-logic-gate-wrapper .pth-truth-table .pth-out-x { color: #92400e; font-weight: 800; }\r\n#pth-logic-gate-wrapper .pth-tt-summary {\r\n    margin-top: 10px; font-size: 13px; font-weight: 700;\r\n    display: flex; gap: 16px; flex-wrap: wrap;\r\n}\r\n#pth-logic-gate-wrapper .pth-tt-chip {\r\n    padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 700;\r\n}\r\n#pth-logic-gate-wrapper .pth-tt-chip-on { background: #dcfce7; color: #15803d; }\r\n#pth-logic-gate-wrapper .pth-tt-chip-off { background: #fee2e2; color: #991b1b; }\r\n\r\n\/* ===== K-MAP ===== *\/\r\n#pth-logic-gate-wrapper .pth-kmap-wrap {\r\n    overflow-x: auto; min-height: 80px;\r\n}\r\n#pth-logic-gate-wrapper .pth-kmap-title {\r\n    font-size: 13px; font-weight: 700; color: #475569; margin-bottom: 10px;\r\n}\r\n#pth-logic-gate-wrapper .pth-kmap-table {\r\n    border-collapse: collapse; font-size: 14px;\r\n    font-family: 'Courier New', monospace; margin: 0 auto;\r\n}\r\n#pth-logic-gate-wrapper .pth-kmap-table th {\r\n    background: #1e293b; color: #fff; padding: 8px 18px;\r\n    text-align: center; font-weight: 800; font-size: 13px;\r\n}\r\n#pth-logic-gate-wrapper .pth-kmap-table td {\r\n    border: 2px solid #cbd5e1; padding: 14px 22px;\r\n    text-align: center; font-size: 20px; font-weight: 800;\r\n    cursor: default; min-width: 56px;\r\n}\r\n#pth-logic-gate-wrapper .pth-kmap-1 { color: #059669; background: #f0fdf4; }\r\n#pth-logic-gate-wrapper .pth-kmap-0 { color: #991b1b; background: #fef2f2; }\r\n#pth-logic-gate-wrapper .pth-kmap-x { color: #92400e; background: #fffbeb; }\r\n#pth-logic-gate-wrapper .pth-kmap-corner {\r\n    background: #f8fafc; border: none; font-size: 11px;\r\n    color: #334155; font-weight: 700; padding: 8px;\r\n}\r\n#pth-logic-gate-wrapper .pth-kmap-note {\r\n    font-size: 12px; color: #334155; margin-top: 10px;\r\n    font-style: italic;\r\n}\r\n\r\n\/* ===== STUDY SAMPLES ===== *\/\r\n#pth-logic-gate-wrapper .pth-study-btn {\r\n    background: #fff; border: 1px solid #7dd3fc; color: #0369a1;\r\n    padding: 6px 12px; border-radius: 6px; font-size: 11px;\r\n    font-weight: 700; cursor: pointer; transition: 0.15s;\r\n    font-family: 'Courier New', monospace; white-space: nowrap;\r\n    display: inline-flex; align-items: center; gap: 4px;\r\n}\r\n#pth-logic-gate-wrapper .pth-study-btn:hover {\r\n    background: #e0f2fe; border-color: #38bdf8; color: #0c4a6e;\r\n}\r\n\r\n\/* ===== GATE COUNT ===== *\/\r\n#pth-logic-gate-wrapper .pth-gate-count-grid {\r\n    display: grid; grid-template-columns: 1fr 1fr;\r\n    gap: 12px; margin-top: 10px;\r\n}\r\n#pth-logic-gate-wrapper .pth-gate-chip {\r\n    background: #f8fafc; border: 1px solid #e2e8f0;\r\n    border-radius: 8px; padding: 12px 16px;\r\n    display: flex; flex-direction: column; gap: 4px;\r\n}\r\n#pth-logic-gate-wrapper .pth-gate-chip-label {\r\n    font-size: 11px; font-weight: 700; color: #334155; text-transform: uppercase;\r\n}\r\n#pth-logic-gate-wrapper .pth-gate-chip-val {\r\n    font-size: 24px; font-weight: 800; color: #0f172a;\r\n}\r\n#pth-logic-gate-wrapper .pth-gate-chip-sub {\r\n    font-size: 11px; color: #334155; font-weight: 600;\r\n}\r\n#pth-logic-gate-wrapper .pth-gate-bar-wrap {\r\n    margin-top: 12px;\r\n}\r\n#pth-logic-gate-wrapper .pth-gate-bar-row {\r\n    display: flex; align-items: center; gap: 10px;\r\n    margin-bottom: 8px; font-size: 13px;\r\n}\r\n#pth-logic-gate-wrapper .pth-gate-bar-label {\r\n    width: 52px; font-weight: 700; font-size: 12px; color: #475569;\r\n    font-family: 'Courier New', monospace;\r\n}\r\n#pth-logic-gate-wrapper .pth-gate-bar-track {\r\n    flex: 1; background: #e2e8f0; border-radius: 99px; height: 10px;\r\n    overflow: hidden;\r\n}\r\n#pth-logic-gate-wrapper .pth-gate-bar-fill {\r\n    height: 100%; border-radius: 99px; transition: width 0.4s ease;\r\n}\r\n#pth-logic-gate-wrapper .pth-gate-bar-num {\r\n    width: 24px; font-weight: 800; color: #0f172a; font-size: 13px;\r\n    text-align: right;\r\n}\r\n\r\n\/* ===== HISTORY PANEL ===== *\/\r\n#pth-logic-gate-wrapper .pth-history-item {\r\n    display: flex; flex-direction: column; gap: 3px;\r\n    padding: 10px; border: 1px solid #e2e8f0; border-radius: 8px;\r\n    margin-bottom: 8px; cursor: pointer; transition: 0.2s;\r\n    background: #f8fafc;\r\n}\r\n#pth-logic-gate-wrapper .pth-history-item:hover { background: #eff6ff; border-color: #bfdbfe; }\r\n#pth-logic-gate-wrapper .pth-history-expr {\r\n    font-family: 'Courier New', monospace; font-size: 12px;\r\n    font-weight: 700; color: #1d4ed8; word-break: break-all;\r\n}\r\n#pth-logic-gate-wrapper .pth-history-meta {\r\n    font-size: 11px; color: #334155; font-weight: 700;\r\n}\r\n#pth-logic-gate-wrapper .pth-history-empty {\r\n    font-size: 13px; color: #475569; text-align: center;\r\n    padding: 20px; font-style: italic;\r\n}\r\n\r\n\/* ===== KEYBOARD ===== *\/\r\n#pth-logic-gate-wrapper .pth-keyboard-grid {\r\n    display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 16px;\r\n}\r\n#pth-logic-gate-wrapper .pth-key-btn {\r\n    background: #fff; border: 1px solid #cbd5e1; color: #334155;\r\n    padding: 9px 4px; border-radius: 6px; font-size: 12px;\r\n    font-weight: 700; cursor: pointer; transition: 0.15s; text-align: center;\r\n    font-family: 'Inter', sans-serif;\r\n}\r\n#pth-logic-gate-wrapper .pth-key-btn:hover { background: #eff6ff; border-color: #3b82f6; color: #1d4ed8; }\r\n#pth-logic-gate-wrapper .pth-key-section-label {\r\n    font-size: 11px; font-weight: 700; color: #334155;\r\n    margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.5px;\r\n}\r\n\r\n\/* Quick formulas *\/\r\n#pth-logic-gate-wrapper .pth-quick-btn {\r\n    background: #f8fafc; border: 1px solid #e2e8f0; color: #334155;\r\n    padding: 8px 12px; border-radius: 6px; font-size: 12px;\r\n    font-weight: 700; cursor: pointer; transition: 0.15s;\r\n    text-align: left; width: 100%; margin-bottom: 6px;\r\n    font-family: 'Courier New', monospace;\r\n}\r\n#pth-logic-gate-wrapper .pth-quick-btn:hover { background: #eff6ff; border-color: #bfdbfe; color: #1d4ed8; }\r\n\r\n\/* Result section cards *\/\r\n#pth-logic-gate-wrapper .pth-result-card {\r\n    background: #fff; border: 1px solid #e2e8f0;\r\n    border-radius: 12px; padding: 20px; margin-bottom: 16px;\r\n}\r\n#pth-logic-gate-wrapper .pth-result-card-nand { border-top: 4px solid #8b5cf6; }\r\n#pth-logic-gate-wrapper .pth-result-card-nor { border-top: 4px solid #ea580c; }\r\n#pth-logic-gate-wrapper .pth-result-card-vhdl { border-top: 4px solid #0891b2; }\r\n#pth-logic-gate-wrapper .pth-result-card-truth { border-top: 4px solid #059669; }\r\n#pth-logic-gate-wrapper .pth-result-card-kmap { border-top: 4px solid #d97706; }\r\n#pth-logic-gate-wrapper .pth-result-card-count { border-top: 4px solid #0f172a; }\r\n\r\n\/* Tab system for output sections *\/\r\n#pth-logic-gate-wrapper .pth-tabs {\r\n    display: flex; gap: 4px; flex-wrap: wrap;\r\n    margin-bottom: 16px; border-bottom: 2px solid #e2e8f0;\r\n    padding-bottom: 0;\r\n}\r\n#pth-logic-gate-wrapper .pth-tab-btn {\r\n    padding: 8px 14px; border-radius: 8px 8px 0 0; font-weight: 700;\r\n    cursor: pointer; border: none; font-family: 'Inter', sans-serif;\r\n    font-size: 12px; transition: 0.2s; background: #f1f5f9;\r\n    color: #334155; margin-bottom: -2px; border: 2px solid transparent;\r\n    border-bottom: none;\r\n}\r\n#pth-logic-gate-wrapper .pth-tab-btn.pth-tab-active {\r\n    background: #fff; color: #1d4ed8; border-color: #e2e8f0;\r\n    border-bottom-color: #fff;\r\n}\r\n#pth-logic-gate-wrapper .pth-tab-content { display: none; }\r\n#pth-logic-gate-wrapper .pth-tab-content.pth-tab-visible { display: block; }\r\n\r\n\/* Sidebar header *\/\r\n#pth-logic-gate-wrapper .pth-sidebar-header {\r\n    background: #f8fafc; margin: -25px -25px 16px -25px;\r\n    padding: 12px 16px; color: #2563eb; font-size: 13px;\r\n    border-bottom: 2px solid #eff6ff; font-weight: 800;\r\n    text-transform: uppercase; border-radius: 12px 12px 0 0;\r\n}\r\n\r\n\/* Info badge row *\/\r\n#pth-logic-gate-wrapper .pth-info-row {\r\n    background: #eff6ff; border: 1px solid #bfdbfe;\r\n    border-radius: 8px; padding: 10px 14px; font-size: 13px;\r\n    color: #1d4ed8; font-weight: 700; margin-bottom: 12px;\r\n}\r\n\r\n\/* Mobile *\/\r\n@media (max-width: 768px) {\r\n    #pth-logic-gate-wrapper { padding: 10px; border-radius: 0; background: transparent; width: 100% !important; }\r\n    #pth-logic-gate-wrapper .pth-card { padding: 14px; margin-bottom: 14px; }\r\n    #pth-logic-gate-wrapper .pth-flex-layout { grid-template-columns: 100% !important; gap: 14px; }\r\n    #pth-logic-gate-wrapper .pth-tool-title { font-size: 20px; }\r\n    #pth-logic-gate-wrapper .pth-gate-count-grid { grid-template-columns: 1fr 1fr; }\r\n    #pth-logic-gate-wrapper .pth-kmap-table td { padding: 10px 14px; font-size: 16px; min-width: 44px; }\r\n    #pth-logic-gate-wrapper .pth-result-card { padding: 14px; }\r\n}\r\n@media print {\r\n    #pth-logic-gate-wrapper .pth-sidebar-col,\r\n    #pth-logic-gate-wrapper .pth-btn-group,\r\n    #pth-logic-gate-wrapper button { display: none !important; }\r\n    #pth-logic-gate-wrapper { background: white; padding: 0; }\r\n    #pth-logic-gate-wrapper .pth-card { border: none; box-shadow: none; }\r\n    #pth-logic-gate-wrapper .pth-code-pre { display: block !important; color: #000; background: #f8fafc; }\r\n}\r\n<\/style>\r\n\r\n<!-- Toast container -->\r\n<div id=\"pth-logic-gate-toast\" role=\"status\" aria-live=\"polite\" style=\"position:fixed;bottom:24px;right:24px;z-index:9999;display:flex;flex-direction:column;gap:10px;pointer-events:none;\"><\/div>\r\n\r\n<div id=\"pth-logic-gate-wrapper\">\r\n    <div class=\"pth-flex-layout\" id=\"pth-logic-gate-layout\">\r\n\r\n        <!-- ======= MAIN COLUMN ======= -->\r\n        <div class=\"pth-main-col\">\r\n            <div class=\"pth-card\">\r\n                <!-- Header -->\r\n                <div style=\"display:flex;justify-content:space-between;align-items:flex-start;margin-bottom:14px;flex-wrap:wrap;gap:10px;\">\r\n                    <h2 class=\"pth-tool-title\">\u26a1 Universal Logic Gate Converter Pro<\/h2>\r\n                    <button class=\"pth-btn pth-btn-secondary\" id=\"pth-fw-btn\" aria-label=\"Toggle full width layout\">\u26f6 Full Width<\/button>\r\n                <\/div>\r\n\r\n                <!-- Meta bar -->\r\n                <div class=\"pth-tool-meta-bar\">\r\n                    <span class=\"pth-version-badge\">v3.1<\/span>\r\n                    <span class=\"pth-status-offline\">\ud83d\udd12 100% Offline<\/span>\r\n                <\/div>\r\n\r\n                <!-- Expression Input -->\r\n                <div class=\"pth-input-group\">\r\n                    <label for=\"pth-formula-input\">Boolean Expression<\/label>\r\n                    <input type=\"text\" id=\"pth-formula-input\" aria-label=\"Boolean expression input\"\r\n                        placeholder=\"e.g., (A AND B) OR (NOT C AND D)\">\r\n                <\/div>\r\n\r\n                <div style=\"display:grid;grid-template-columns:1fr 1fr;gap:12px;margin-bottom:16px;\">\r\n                    <div>\r\n                        <label for=\"pth-vars-display\">Detected Variables<\/label>\r\n                        <input type=\"text\" id=\"pth-vars-display\" aria-label=\"Auto-detected variables\" readonly placeholder=\"Auto-detected\">\r\n                    <\/div>\r\n                    <div>\r\n                        <label for=\"pth-var-count-display\">Variable Count<\/label>\r\n                        <input type=\"text\" id=\"pth-var-count-display\" aria-label=\"Number of variables detected\" readonly placeholder=\"\u2014\">\r\n                    <\/div>\r\n                <\/div>\r\n\r\n                <!-- Action bar -->\r\n                <div class=\"pth-btn-group\">\r\n                    <button class=\"pth-btn pth-btn-primary\" id=\"pth-convert-btn\" aria-label=\"Convert and analyze the boolean expression\">\u2728 Convert & Analyze<\/button>\r\n                    <button class=\"pth-sample-btn\" id=\"pth-sample-btn\" aria-label=\"Load sample boolean expression\">\ud83d\udca1 Load Sample<\/button>\r\n                    <button class=\"pth-btn pth-btn-secondary\" id=\"pth-export-btn\" aria-label=\"Export all code as a text file\">\ud83d\udcbe Export All<\/button>\r\n                    <button class=\"pth-btn pth-btn-secondary\" id=\"pth-print-btn\" aria-label=\"Print results\">\ud83d\udda8\ufe0f Print<\/button>\r\n                    <button class=\"pth-btn pth-btn-danger\" id=\"pth-clear-btn\" aria-label=\"Clear all inputs and results\" style=\"padding:8px 14px;\">\ud83d\uddd1\ufe0f Clear<\/button>\r\n                <\/div>\r\n\r\n                <!-- Error box -->\r\n                <div class=\"pth-error-box\" id=\"pth-error-box\" role=\"alert\" aria-live=\"assertive\"><\/div>\r\n            <\/div>\r\n\r\n            <!-- Results Area -->\r\n            <div id=\"pth-results-area\" class=\"pth-output-area\" style=\"display:none;\">\r\n\r\n                <!-- Tab navigation -->\r\n                <div class=\"pth-tabs\" role=\"tablist\" aria-label=\"Result sections\">\r\n                    <button class=\"pth-tab-btn pth-tab-active\" role=\"tab\" aria-selected=\"true\" data-tab=\"simplify\" aria-controls=\"pth-tab-simplify\">\ud83d\udcd0 Simplify<\/button>\r\n                    <button class=\"pth-tab-btn\" role=\"tab\" aria-selected=\"false\" data-tab=\"nand\" aria-controls=\"pth-tab-nand\">\ud83d\udfe3 NAND<\/button>\r\n                    <button class=\"pth-tab-btn\" role=\"tab\" aria-selected=\"false\" data-tab=\"nor\" aria-controls=\"pth-tab-nor\">\ud83d\udfe0 NOR<\/button>\r\n                    <button class=\"pth-tab-btn\" role=\"tab\" aria-selected=\"false\" data-tab=\"vhdl\" aria-controls=\"pth-tab-vhdl\">\ud83d\udca0 VHDL<\/button>\r\n                    <button class=\"pth-tab-btn\" role=\"tab\" aria-selected=\"false\" data-tab=\"truth\" aria-controls=\"pth-tab-truth\">\ud83d\udcca Truth Table<\/button>\r\n                    <button class=\"pth-tab-btn\" role=\"tab\" aria-selected=\"false\" data-tab=\"kmap\" aria-controls=\"pth-tab-kmap\">\ud83d\uddc2\ufe0f K-Map<\/button>\r\n                    <button class=\"pth-tab-btn\" role=\"tab\" aria-selected=\"false\" data-tab=\"count\" aria-controls=\"pth-tab-count\">\ud83d\udd22 Gate Count<\/button>\r\n                    <button class=\"pth-tab-btn\" role=\"tab\" aria-selected=\"false\" data-tab=\"raw\" aria-controls=\"pth-tab-raw\">\ud83d\udcc2 Raw Data<\/button>\r\n                <\/div>\r\n\r\n                <!-- Tab: Simplify -->\r\n                <div class=\"pth-tab-content pth-tab-visible\" id=\"pth-tab-simplify\" role=\"tabpanel\">\r\n                    <div class=\"pth-result-card\">\r\n                        <h3 class=\"pth-section-header\">\ud83d\udcd0 Step-by-Step Simplification<\/h3>\r\n                        <div id=\"pth-simplification-steps\" class=\"pth-steps-container\"><\/div>\r\n                        <div style=\"background:#f0fdf4;border:1px solid #bbf7d0;padding:12px 16px;border-radius:8px;margin-top:12px;\">\r\n                            <span style=\"font-size:12px;font-weight:700;color:#334155;text-transform:uppercase;\">Final Minimized Expression:<\/span>\r\n                            <div class=\"pth-simplified-display\" id=\"pth-simplified-display\"><\/div>\r\n                        <\/div>\r\n                    <\/div>\r\n                <\/div>\r\n\r\n                <!-- Tab: NAND -->\r\n                <div class=\"pth-tab-content\" id=\"pth-tab-nand\" role=\"tabpanel\">\r\n                    <div class=\"pth-result-card pth-result-card-nand\">\r\n                        <h3 class=\"pth-section-header\">\ud83d\udfe3 Optimized NAND Implementation<\/h3>\r\n                        <div id=\"pth-nand-display\" class=\"pth-formula-box pth-nand-accent\"><\/div>\r\n                        <div class=\"pth-action-bar\">\r\n                            <button class=\"pth-btn pth-btn-purple\" id=\"pth-nand-toggle-btn\" aria-label=\"Show or hide NAND Verilog code\">Show Verilog<\/button>\r\n                            <button class=\"pth-btn pth-btn-secondary\" id=\"pth-nand-copy-btn\" aria-label=\"Copy NAND Verilog code\">\ud83d\udccb Copy Verilog<\/button>\r\n                            <button class=\"pth-btn pth-btn-success\" id=\"pth-nand-sim-btn\" aria-label=\"Simulate NAND circuit in DigitalJS\">\u25b6 Simulate<\/button>\r\n                        <\/div>\r\n                        <pre id=\"pth-nand-verilog\" class=\"pth-code-pre\" aria-label=\"NAND Verilog code\"><\/pre>\r\n                    <\/div>\r\n                <\/div>\r\n\r\n                <!-- Tab: NOR -->\r\n                <div class=\"pth-tab-content\" id=\"pth-tab-nor\" role=\"tabpanel\">\r\n                    <div class=\"pth-result-card pth-result-card-nor\">\r\n                        <h3 class=\"pth-section-header\">\ud83d\udfe0 Optimized NOR Implementation<\/h3>\r\n                        <div id=\"pth-nor-display\" class=\"pth-formula-box pth-nor-accent\"><\/div>\r\n                        <div class=\"pth-action-bar\">\r\n                            <button class=\"pth-btn pth-btn-orange\" id=\"pth-nor-toggle-btn\" aria-label=\"Show or hide NOR Verilog code\">Show Verilog<\/button>\r\n                            <button class=\"pth-btn pth-btn-secondary\" id=\"pth-nor-copy-btn\" aria-label=\"Copy NOR Verilog code\">\ud83d\udccb Copy Verilog<\/button>\r\n                            <button class=\"pth-btn pth-btn-success\" id=\"pth-nor-sim-btn\" aria-label=\"Simulate NOR circuit in DigitalJS\">\u25b6 Simulate<\/button>\r\n                        <\/div>\r\n                        <pre id=\"pth-nor-verilog\" class=\"pth-code-pre\" aria-label=\"NOR Verilog code\"><\/pre>\r\n                    <\/div>\r\n                <\/div>\r\n\r\n                <!-- Tab: VHDL -->\r\n                <div class=\"pth-tab-content\" id=\"pth-tab-vhdl\" role=\"tabpanel\">\r\n                    <div class=\"pth-result-card pth-result-card-vhdl\">\r\n                        <h3 class=\"pth-section-header\">\ud83d\udca0 VHDL Export<\/h3>\r\n                        <div class=\"pth-info-row\">VHDL (VHSIC Hardware Description Language) \u2014 for FPGA\/ASIC synthesis workflows.<\/div>\r\n\r\n                        <div style=\"margin-bottom:16px;\">\r\n                            <h4 style=\"font-size:13px;color:#475569;text-transform:uppercase;margin-bottom:8px;\">Original Logic \u2014 VHDL<\/h4>\r\n                            <div class=\"pth-action-bar\" style=\"margin-top:0;margin-bottom:8px;\">\r\n                                <button class=\"pth-btn pth-btn-secondary\" id=\"pth-vhdl-orig-toggle-btn\" aria-label=\"Show or hide original VHDL code\">Show Code<\/button>\r\n                                <button class=\"pth-btn pth-btn-secondary\" id=\"pth-vhdl-orig-copy-btn\" aria-label=\"Copy original VHDL code\">\ud83d\udccb Copy<\/button>\r\n                            <\/div>\r\n                            <pre id=\"pth-orig-vhdl\" class=\"pth-code-pre\" aria-label=\"Original VHDL code\" style=\"color:#7dd3fc;\"><\/pre>\r\n                        <\/div>\r\n\r\n                        <div style=\"margin-bottom:16px;\">\r\n                            <h4 style=\"font-size:13px;color:#475569;text-transform:uppercase;margin-bottom:8px;\">Simplified Logic \u2014 VHDL<\/h4>\r\n                            <div class=\"pth-action-bar\" style=\"margin-top:0;margin-bottom:8px;\">\r\n                                <button class=\"pth-btn pth-btn-secondary\" id=\"pth-vhdl-simp-toggle-btn\" aria-label=\"Show or hide simplified VHDL code\">Show Code<\/button>\r\n                                <button class=\"pth-btn pth-btn-secondary\" id=\"pth-vhdl-simp-copy-btn\" aria-label=\"Copy simplified VHDL code\">\ud83d\udccb Copy<\/button>\r\n                            <\/div>\r\n                            <pre id=\"pth-simp-vhdl\" class=\"pth-code-pre\" aria-label=\"Simplified VHDL code\" style=\"color:#7dd3fc;\"><\/pre>\r\n                        <\/div>\r\n\r\n                        <div style=\"margin-bottom:16px;\">\r\n                            <h4 style=\"font-size:13px;color:#4c1d95;text-transform:uppercase;margin-bottom:8px;\">NAND-Only \u2014 VHDL<\/h4>\r\n                            <div class=\"pth-action-bar\" style=\"margin-top:0;margin-bottom:8px;\">\r\n                                <button class=\"pth-btn pth-btn-secondary\" id=\"pth-vhdl-nand-toggle-btn\" aria-label=\"Show or hide NAND VHDL code\">Show Code<\/button>\r\n                                <button class=\"pth-btn pth-btn-secondary\" id=\"pth-vhdl-nand-copy-btn\" aria-label=\"Copy NAND VHDL code\">\ud83d\udccb Copy<\/button>\r\n                            <\/div>\r\n                            <pre id=\"pth-nand-vhdl\" class=\"pth-code-pre\" aria-label=\"NAND VHDL code\" style=\"color:#c4b5fd;\"><\/pre>\r\n                        <\/div>\r\n\r\n                        <div>\r\n                            <h4 style=\"font-size:13px;color:#ea580c;text-transform:uppercase;margin-bottom:8px;\">NOR-Only \u2014 VHDL<\/h4>\r\n                            <div class=\"pth-action-bar\" style=\"margin-top:0;margin-bottom:8px;\">\r\n                                <button class=\"pth-btn pth-btn-secondary\" id=\"pth-vhdl-nor-toggle-btn\" aria-label=\"Show or hide NOR VHDL code\">Show Code<\/button>\r\n                                <button class=\"pth-btn pth-btn-secondary\" id=\"pth-vhdl-nor-copy-btn\" aria-label=\"Copy NOR VHDL code\">\ud83d\udccb Copy<\/button>\r\n                            <\/div>\r\n                            <pre id=\"pth-nor-vhdl\" class=\"pth-code-pre\" aria-label=\"NOR VHDL code\" style=\"color:#fdba74;\"><\/pre>\r\n                        <\/div>\r\n                    <\/div>\r\n                <\/div>\r\n\r\n                <!-- Tab: Truth Table -->\r\n                <div class=\"pth-tab-content\" id=\"pth-tab-truth\" role=\"tabpanel\">\r\n                    <div class=\"pth-result-card pth-result-card-truth\">\r\n                        <h3 class=\"pth-section-header\">\r\n                            \ud83d\udcca Truth Table\r\n                            <button class=\"pth-btn pth-btn-secondary\" id=\"pth-tt-copy-btn\" aria-label=\"Copy truth table as CSV\" style=\"padding:6px 12px;font-size:12px;\">\ud83d\udccb Copy CSV<\/button>\r\n                        <\/h3>\r\n                        <div class=\"pth-truth-table-wrap\">\r\n                            <div id=\"pth-truth-table-container\" class=\"pth-output-area\"><\/div>\r\n                        <\/div>\r\n                        <div class=\"pth-tt-summary\" id=\"pth-tt-summary\"><\/div>\r\n                    <\/div>\r\n                <\/div>\r\n\r\n                <!-- Tab: K-Map -->\r\n                <div class=\"pth-tab-content\" id=\"pth-tab-kmap\" role=\"tabpanel\">\r\n                    <div class=\"pth-result-card pth-result-card-kmap\">\r\n                        <h3 class=\"pth-section-header\">\ud83d\uddc2\ufe0f Karnaugh Map (K-Map)<\/h3>\r\n                        <div id=\"pth-kmap-container\" class=\"pth-kmap-wrap pth-output-area\"><\/div>\r\n                    <\/div>\r\n                <\/div>\r\n\r\n                <!-- Tab: Gate Count -->\r\n                <div class=\"pth-tab-content\" id=\"pth-tab-count\" role=\"tabpanel\">\r\n                    <div class=\"pth-result-card pth-result-card-count\">\r\n                        <h3 class=\"pth-section-header\">\ud83d\udd22 Gate Count Analyzer<\/h3>\r\n\r\n                        <!-- Study Samples Panel -->\r\n                        <div id=\"pth-study-samples-panel\" style=\"background:#f0f9ff;border:1px solid #bae6fd;border-radius:10px;padding:14px 16px;margin-bottom:18px;\">\r\n                            <div style=\"font-size:12px;font-weight:800;color:#0369a1;text-transform:uppercase;letter-spacing:0.5px;margin-bottom:10px;\">\ud83d\udcda Study Samples \u2014 Click to Load &amp; Compare Gate Counts<\/div>\r\n                            <div id=\"pth-study-sample-btns\" style=\"display:flex;flex-wrap:wrap;gap:8px;\"><\/div>\r\n                        <\/div>\r\n\r\n                        <div style=\"display:grid;grid-template-columns:1fr 1fr;gap:16px;\">\r\n                            <div>\r\n                                <div style=\"font-size:13px;font-weight:800;color:#5b21b6;margin-bottom:10px;text-transform:uppercase;\">NAND Implementation<\/div>\r\n                                <div class=\"pth-gate-count-grid\" id=\"pth-nand-count-grid\"><\/div>\r\n                                <div class=\"pth-gate-bar-wrap\" id=\"pth-nand-bar-wrap\"><\/div>\r\n                            <\/div>\r\n                            <div>\r\n                                <div style=\"font-size:13px;font-weight:800;color:#c2410c;margin-bottom:10px;text-transform:uppercase;\">NOR Implementation<\/div>\r\n                                <div class=\"pth-gate-count-grid\" id=\"pth-nor-count-grid\"><\/div>\r\n                                <div class=\"pth-gate-bar-wrap\" id=\"pth-nor-bar-wrap\"><\/div>\r\n                            <\/div>\r\n                        <\/div>\r\n                        <div id=\"pth-gate-verdict\" style=\"margin-top:16px;padding:12px 16px;border-radius:8px;font-size:14px;font-weight:700;\"><\/div>\r\n                    <\/div>\r\n                <\/div>\r\n\r\n                <!-- Tab: Raw Data -->\r\n                <div class=\"pth-tab-content\" id=\"pth-tab-raw\" role=\"tabpanel\">\r\n                    <div class=\"pth-result-card\">\r\n                        <h3 class=\"pth-section-header\">\ud83d\udcc2 Raw Conversion Data<\/h3>\r\n\r\n                        <div style=\"margin-bottom:16px;\">\r\n                            <div style=\"font-size:12px;font-weight:700;color:#475569;text-transform:uppercase;margin-bottom:6px;\">Original Verilog<\/div>\r\n                            <div class=\"pth-action-bar\" style=\"margin-top:0;margin-bottom:8px;\">\r\n                                <button class=\"pth-btn pth-btn-secondary\" id=\"pth-raw-orig-toggle-btn\" aria-label=\"Toggle original Verilog\">Show \/ Hide<\/button>\r\n                                <button class=\"pth-btn pth-btn-secondary\" id=\"pth-raw-orig-copy-btn\" aria-label=\"Copy original Verilog\">\ud83d\udccb Copy<\/button>\r\n                            <\/div>\r\n                            <pre id=\"pth-original-verilog\" class=\"pth-code-pre\" aria-label=\"Original Verilog code\"><\/pre>\r\n                        <\/div>\r\n\r\n                        <div style=\"margin-bottom:16px;\">\r\n                            <div style=\"font-size:12px;font-weight:700;color:#4c1d95;text-transform:uppercase;margin-bottom:6px;\">Raw Unsimplified NAND<\/div>\r\n                            <div id=\"pth-raw-nand\" class=\"pth-formula-box pth-nand-accent\" style=\"font-size:13px;\"><\/div>\r\n                        <\/div>\r\n\r\n                        <div>\r\n                            <div style=\"font-size:12px;font-weight:700;color:#ea580c;text-transform:uppercase;margin-bottom:6px;\">Raw Unsimplified NOR<\/div>\r\n                            <div id=\"pth-raw-nor\" class=\"pth-formula-box pth-nor-accent\" style=\"font-size:13px;\"><\/div>\r\n                        <\/div>\r\n                    <\/div>\r\n                <\/div>\r\n\r\n            <\/div><!-- end results area -->\r\n        <\/div><!-- end main col -->\r\n\r\n        <!-- ======= SIDEBAR COLUMN ======= -->\r\n        <div class=\"pth-sidebar-col\" id=\"pth-logic-gate-sidebar\">\r\n\r\n            <!-- History Panel -->\r\n            <div class=\"pth-card\">\r\n                <h3 class=\"pth-sidebar-header\">\ud83d\udd53 Recent History<\/h3>\r\n                <div id=\"pth-history-container\">\r\n                    <div class=\"pth-history-empty\">No conversions yet.<br>Run an analysis to see history.<\/div>\r\n                <\/div>\r\n                <button class=\"pth-btn pth-btn-danger\" id=\"pth-clear-history-btn\" aria-label=\"Clear conversion history\" style=\"width:100%;margin-top:10px;font-size:12px;padding:8px;\">\ud83d\uddd1\ufe0f Clear History<\/button>\r\n            <\/div>\r\n\r\n            <!-- Virtual Logic Keyboard -->\r\n            <div class=\"pth-card\">\r\n                <h3 class=\"pth-sidebar-header\">\u2328\ufe0f Logic Keyboard<\/h3>\r\n                <div class=\"pth-key-section-label\">Operators<\/div>\r\n                <div class=\"pth-keyboard-grid\">\r\n                    <button class=\"pth-key-btn\" data-token=\"AND\" aria-label=\"Insert AND operator\">AND<\/button>\r\n                    <button class=\"pth-key-btn\" data-token=\"OR\" aria-label=\"Insert OR operator\">OR<\/button>\r\n                    <button class=\"pth-key-btn\" data-token=\"NOT\" aria-label=\"Insert NOT operator\">NOT<\/button>\r\n                    <button class=\"pth-key-btn\" data-token=\"XOR\" aria-label=\"Insert XOR operator\">XOR<\/button>\r\n                    <button class=\"pth-key-btn\" data-token=\"NAND\" aria-label=\"Insert NAND operator\">NAND<\/button>\r\n                    <button class=\"pth-key-btn\" data-token=\"NOR\" aria-label=\"Insert NOR operator\">NOR<\/button>\r\n                    <button class=\"pth-key-btn\" data-token=\"XNOR\" aria-label=\"Insert XNOR operator\">XNOR<\/button>\r\n                    <button class=\"pth-key-btn\" data-token=\"IMPLIES\" aria-label=\"Insert IMPLIES operator\" style=\"font-size:10px;\">IMPLIES<\/button>\r\n                    <button class=\"pth-key-btn\" data-token=\"(\" aria-label=\"Insert open parenthesis\">(<\/button>\r\n                    <button class=\"pth-key-btn\" data-token=\")\" aria-label=\"Insert close parenthesis\">)<\/button>\r\n                    <button class=\"pth-key-btn\" data-token=\"1\" aria-label=\"Insert constant 1\">1<\/button>\r\n                    <button class=\"pth-key-btn\" data-token=\"0\" aria-label=\"Insert constant 0\">0<\/button>\r\n                <\/div>\r\n                <div class=\"pth-key-section-label\">Variables<\/div>\r\n                <div class=\"pth-keyboard-grid\">\r\n                    <button class=\"pth-key-btn\" data-token=\"A\" aria-label=\"Insert variable A\">A<\/button>\r\n                    <button class=\"pth-key-btn\" data-token=\"B\" aria-label=\"Insert variable B\">B<\/button>\r\n                    <button class=\"pth-key-btn\" data-token=\"C\" aria-label=\"Insert variable C\">C<\/button>\r\n                    <button class=\"pth-key-btn\" data-token=\"D\" aria-label=\"Insert variable D\">D<\/button>\r\n                    <button class=\"pth-key-btn\" data-token=\"E\" aria-label=\"Insert variable E\">E<\/button>\r\n                    <button class=\"pth-key-btn\" data-token=\"F\" aria-label=\"Insert variable F\">F<\/button>\r\n                <\/div>\r\n            <\/div>\r\n\r\n            <!-- Quick Formulas -->\r\n            <div class=\"pth-card\">\r\n                <h3 class=\"pth-sidebar-header\">\u26a1 Quick Formulas<\/h3>\r\n                <button class=\"pth-quick-btn\" data-formula=\"A XOR B\" aria-label=\"Load half adder sum formula\">Half Adder Sum (XOR)<\/button>\r\n                <button class=\"pth-quick-btn\" data-formula=\"(A AND B) OR (C AND NOT D)\" aria-label=\"Load multiplexer logic formula\">Multiplexer Logic<\/button>\r\n                <button class=\"pth-quick-btn\" data-formula=\"A IMPLIES B\" aria-label=\"Load implication formula\">Implication (A \u2192 B)<\/button>\r\n                <button class=\"pth-quick-btn\" data-formula=\"NOT(A AND B) OR NOT(C OR D)\" aria-label=\"Load De Morgan test formula\">De Morgan Test<\/button>\r\n                <button class=\"pth-quick-btn\" data-formula=\"(A AND B) XOR (C XNOR D)\" aria-label=\"Load XOR XNOR combo formula\">XOR \/ XNOR Combo<\/button>\r\n                <button class=\"pth-quick-btn\" data-formula=\"(A OR B) AND (NOT A OR C) AND (NOT B OR NOT C)\" aria-label=\"Load 3-variable CNF formula\">3-Variable CNF<\/button>\r\n                <button class=\"pth-quick-btn\" data-formula=\"A AND NOT A\" aria-label=\"Load contradiction formula\">Contradiction (0)<\/button>\r\n                <button class=\"pth-quick-btn\" data-formula=\"A OR NOT A\" aria-label=\"Load tautology formula\">Tautology (1)<\/button>\r\n            <\/div>\r\n\r\n        <\/div><!-- end sidebar -->\r\n\r\n    <\/div><!-- end flex layout -->\r\n<\/div><!-- end wrapper -->\r\n\r\n<script data-no-optimize=\"1\" data-no-minify=\"1\" data-cfasync=\"false\">\r\n(function () {\r\n    'use strict';\r\n\r\n    \/* =====================================================\r\n       WINDOW APP OBJECT\r\n       ===================================================== *\/\r\n    window.pthLogicGateApp = {\r\n        initialized: false,\r\n        currentResult: null,\r\n        historyKey: 'pth_lgc_history',\r\n\r\n        \/* \u2500\u2500\u2500 INIT \u2500\u2500\u2500 *\/\r\n        init: function () {\r\n            this.attachEvents();\r\n            this.loadHistory();\r\n            this.initStudySamples();\r\n        },\r\n\r\n        \/* \u2500\u2500\u2500 EVENTS \u2500\u2500\u2500 *\/\r\n        attachEvents: function () {\r\n            var self = this;\r\n            var formula = document.getElementById('pth-formula-input');\r\n            if (formula) {\r\n                formula.addEventListener('input', function () { self.updateVars(); });\r\n                formula.addEventListener('keydown', function (e) {\r\n                    if (e.key === 'Enter') { self.process(); }\r\n                });\r\n            }\r\n\r\n            var cvt = document.getElementById('pth-convert-btn');\r\n            if (cvt) cvt.addEventListener('click', function () { self.process(); });\r\n\r\n            var smpl = document.getElementById('pth-sample-btn');\r\n            if (smpl) smpl.addEventListener('click', function () { self.loadSample(); });\r\n\r\n            var clr = document.getElementById('pth-clear-btn');\r\n            if (clr) clr.addEventListener('click', function () { self.clearAll(); });\r\n\r\n            var exp = document.getElementById('pth-export-btn');\r\n            if (exp) exp.addEventListener('click', function () { self.exportAll(); });\r\n\r\n            var prnt = document.getElementById('pth-print-btn');\r\n            if (prnt) prnt.addEventListener('click', function () { window.print(); });\r\n\r\n            var fw = document.getElementById('pth-fw-btn');\r\n            if (fw) fw.addEventListener('click', function () { self.toggleWidth(); });\r\n\r\n            \/* Tabs *\/\r\n            var tabs = document.querySelectorAll('#pth-logic-gate-wrapper .pth-tab-btn');\r\n            for (var i = 0; i < tabs.length; i++) {\r\n                (function (btn) {\r\n                    btn.addEventListener('click', function () { self.switchTab(btn.getAttribute('data-tab')); });\r\n                })(tabs[i]);\r\n            }\r\n\r\n            \/* Logic keyboard *\/\r\n            var keyBtns = document.querySelectorAll('#pth-logic-gate-wrapper .pth-key-btn');\r\n            for (var k = 0; k < keyBtns.length; k++) {\r\n                (function (btn) {\r\n                    btn.addEventListener('click', function () { self.addToken(btn.getAttribute('data-token')); });\r\n                })(keyBtns[k]);\r\n            }\r\n\r\n            \/* Quick formulas *\/\r\n            var quickBtns = document.querySelectorAll('#pth-logic-gate-wrapper .pth-quick-btn');\r\n            for (var q = 0; q < quickBtns.length; q++) {\r\n                (function (btn) {\r\n                    btn.addEventListener('click', function () { self.loadFormula(btn.getAttribute('data-formula')); });\r\n                })(quickBtns[q]);\r\n            }\r\n\r\n            \/* NAND \/ NOR toggles + copy + simulate *\/\r\n            var nandTog = document.getElementById('pth-nand-toggle-btn');\r\n            if (nandTog) nandTog.addEventListener('click', function () { self.toggleCode('pth-nand-verilog', this); });\r\n\r\n            var norTog = document.getElementById('pth-nor-toggle-btn');\r\n            if (norTog) norTog.addEventListener('click', function () { self.toggleCode('pth-nor-verilog', this); });\r\n\r\n            var nandCpy = document.getElementById('pth-nand-copy-btn');\r\n            if (nandCpy) nandCpy.addEventListener('click', function () { self.copyCode('pth-nand-verilog'); });\r\n\r\n            var norCpy = document.getElementById('pth-nor-copy-btn');\r\n            if (norCpy) norCpy.addEventListener('click', function () { self.copyCode('pth-nor-verilog'); });\r\n\r\n            var nandSim = document.getElementById('pth-nand-sim-btn');\r\n            if (nandSim) nandSim.addEventListener('click', function () { self.simulate('pth-nand-verilog'); });\r\n\r\n            var norSim = document.getElementById('pth-nor-sim-btn');\r\n            if (norSim) norSim.addEventListener('click', function () { self.simulate('pth-nor-verilog'); });\r\n\r\n            \/* VHDL toggles *\/\r\n            var vhdlPairs = [\r\n                ['pth-vhdl-orig-toggle-btn', 'pth-orig-vhdl'],\r\n                ['pth-vhdl-simp-toggle-btn', 'pth-simp-vhdl'],\r\n                ['pth-vhdl-nand-toggle-btn', 'pth-nand-vhdl'],\r\n                ['pth-vhdl-nor-toggle-btn',  'pth-nor-vhdl'],\r\n                ['pth-raw-orig-toggle-btn',  'pth-original-verilog']\r\n            ];\r\n            for (var vp = 0; vp < vhdlPairs.length; vp++) {\r\n                (function (pair) {\r\n                    var btn = document.getElementById(pair[0]);\r\n                    if (btn) btn.addEventListener('click', function () { self.toggleCode(pair[1], this); });\r\n                })(vhdlPairs[vp]);\r\n            }\r\n\r\n            \/* VHDL copy buttons *\/\r\n            var copyPairs = [\r\n                ['pth-vhdl-orig-copy-btn', 'pth-orig-vhdl'],\r\n                ['pth-vhdl-simp-copy-btn', 'pth-simp-vhdl'],\r\n                ['pth-vhdl-nand-copy-btn', 'pth-nand-vhdl'],\r\n                ['pth-vhdl-nor-copy-btn',  'pth-nor-vhdl'],\r\n                ['pth-raw-orig-copy-btn',  'pth-original-verilog']\r\n            ];\r\n            for (var cp = 0; cp < copyPairs.length; cp++) {\r\n                (function (pair) {\r\n                    var btn = document.getElementById(pair[0]);\r\n                    if (btn) btn.addEventListener('click', function () { self.copyCode(pair[1]); });\r\n                })(copyPairs[cp]);\r\n            }\r\n\r\n            \/* Truth table copy *\/\r\n            var ttCpy = document.getElementById('pth-tt-copy-btn');\r\n            if (ttCpy) ttCpy.addEventListener('click', function () { self.copyTruthTableCSV(); });\r\n\r\n            \/* Clear history *\/\r\n            var clrHist = document.getElementById('pth-clear-history-btn');\r\n            if (clrHist) clrHist.addEventListener('click', function () { self.clearHistory(); });\r\n        },\r\n\r\n        \/* \u2500\u2500\u2500 TABS \u2500\u2500\u2500 *\/\r\n        switchTab: function (tab) {\r\n            var btns = document.querySelectorAll('#pth-logic-gate-wrapper .pth-tab-btn');\r\n            var panels = document.querySelectorAll('#pth-logic-gate-wrapper .pth-tab-content');\r\n            for (var i = 0; i < btns.length; i++) {\r\n                btns[i].classList.remove('pth-tab-active');\r\n                btns[i].setAttribute('aria-selected', 'false');\r\n            }\r\n            for (var j = 0; j < panels.length; j++) {\r\n                panels[j].classList.remove('pth-tab-visible');\r\n            }\r\n            var activeBtn = document.querySelector('[data-tab=\"' + tab + '\"]');\r\n            var activePanel = document.getElementById('pth-tab-' + tab);\r\n            if (activeBtn) { activeBtn.classList.add('pth-tab-active'); activeBtn.setAttribute('aria-selected', 'true'); }\r\n            if (activePanel) activePanel.classList.add('pth-tab-visible');\r\n        },\r\n\r\n        \/* \u2500\u2500\u2500 VARS \u2500\u2500\u2500 *\/\r\n        updateVars: function () {\r\n            var val = (document.getElementById('pth-formula-input').value || '').toUpperCase();\r\n            var stripped = val.replace(\/\\b(AND|OR|NOT|XOR|NAND|NOR|XNOR|IMPLIES)\\b\/g, '');\r\n            var matches = stripped.match(\/[A-F]\/g);\r\n            var unique = matches ? [...new Set(matches)].sort() : [];\r\n            document.getElementById('pth-vars-display').value = unique.join(', ') || '';\r\n            document.getElementById('pth-var-count-display').value = unique.length ? unique.length + ' variable' + (unique.length > 1 ? 's' : '') : '';\r\n            return unique;\r\n        },\r\n\r\n        \/* \u2500\u2500\u2500 TOKENS \u2500\u2500\u2500 *\/\r\n        addToken: function (val) {\r\n            var el = document.getElementById('pth-formula-input');\r\n            if (!el) return;\r\n            var space = el.value.length > 0 && !el.value.endsWith(' ') ? ' ' : '';\r\n            el.value = el.value + space + val;\r\n            el.dispatchEvent(new Event('input'));\r\n            el.focus();\r\n        },\r\n\r\n        \/* \u2500\u2500\u2500 FULL WIDTH \u2500\u2500\u2500 *\/\r\n        toggleWidth: function () {\r\n            var layout = document.getElementById('pth-logic-gate-layout');\r\n            var sidebar = document.getElementById('pth-logic-gate-sidebar');\r\n            var btn = document.getElementById('pth-fw-btn');\r\n            if (!layout || !sidebar || !btn) return;\r\n            if (layout.classList.contains('pth-full-width')) {\r\n                layout.classList.remove('pth-full-width');\r\n                sidebar.style.display = '';\r\n                btn.textContent = '\\u29c6 Full Width';\r\n            } else {\r\n                layout.classList.add('pth-full-width');\r\n                sidebar.style.display = 'none';\r\n                btn.textContent = '\\u25e8 Split View';\r\n            }\r\n        },\r\n\r\n        \/* \u2500\u2500\u2500 LOAD SAMPLE \u2500\u2500\u2500 *\/\r\n        loadSample: function () {\r\n            document.getElementById('pth-formula-input').value = '(A AND B) OR (NOT C AND D)';\r\n            this.updateVars();\r\n            this.showToast('Sample loaded!', 'success');\r\n        },\r\n\r\n        \/* \u2500\u2500\u2500 STUDY SAMPLES DATA \u2500\u2500\u2500 *\/\r\n        studySamples: [\r\n            { label: '\ud83d\udca1 Half Adder',         formula: 'A XOR B' },\r\n            { label: '\u2795 Full Adder Carry',      formula: '(A AND B) OR (B AND C) OR (A AND C)' },\r\n            { label: '\ud83d\udd00 2-to-1 MUX',          formula: '(A AND NOT S) OR (B AND S)' },\r\n            { label: '\ud83d\udd17 4-input AND Chain',   formula: 'A AND B AND C AND D' },\r\n            { label: '\ud83e\uddea De Morgan Test',       formula: 'NOT(A AND B) OR NOT(C OR D)' },\r\n            { label: '\ud83d\udcdc 3-Var CNF',            formula: '(A OR B) AND (NOT A OR C) AND (NOT B OR NOT C)' },\r\n            { label: '\u267e Tautology (1)',           formula: 'A OR NOT A' },\r\n            { label: '\u00d7 Contradiction (0)',       formula: 'A AND NOT A' }\r\n        ],\r\n\r\n        \/* \u2500\u2500\u2500 INIT STUDY SAMPLE BUTTONS \u2500\u2500\u2500 *\/\r\n        initStudySamples: function () {\r\n            var self = this;\r\n            var container = document.getElementById('pth-study-sample-btns');\r\n            if (!container) return;\r\n            var html = '';\r\n            for (var i = 0; i < self.studySamples.length; i++) {\r\n                html += '<button class=\"pth-study-btn\" data-study-formula=\"' + self.studySamples[i].formula + '\" aria-label=\"Load study sample: ' + self.studySamples[i].label + '\">' + self.studySamples[i].label + '<\/button>';\r\n            }\r\n            container.innerHTML = html;\r\n            var btns = container.querySelectorAll('.pth-study-btn');\r\n            for (var j = 0; j < btns.length; j++) {\r\n                (function (btn) {\r\n                    btn.addEventListener('click', function () {\r\n                        var f = btn.getAttribute('data-study-formula');\r\n                        document.getElementById('pth-formula-input').value = f;\r\n                        self.updateVars();\r\n                        self.process();\r\n                        \/* Switch to Gate Count tab after processing *\/\r\n                        setTimeout(function () { self.switchTab('count'); }, 80);\r\n                        self.showToast('Study sample loaded!', 'success');\r\n                    });\r\n                })(btns[j]);\r\n            }\r\n        },\r\n\r\n        \/* \u2500\u2500\u2500 LOAD FORMULA \u2500\u2500\u2500 *\/\r\n        loadFormula: function (f) {\r\n            document.getElementById('pth-formula-input').value = f;\r\n            this.updateVars();\r\n            this.process();\r\n        },\r\n\r\n        \/* \u2500\u2500\u2500 CLEAR ALL \u2500\u2500\u2500 *\/\r\n        clearAll: function () {\r\n            document.getElementById('pth-formula-input').value = '';\r\n            document.getElementById('pth-vars-display').value = '';\r\n            document.getElementById('pth-var-count-display').value = '';\r\n            document.getElementById('pth-results-area').style.display = 'none';\r\n            document.getElementById('pth-error-box').style.display = 'none';\r\n            document.getElementById('pth-error-box').textContent = '';\r\n            this.currentResult = null;\r\n            this.showToast('Cleared!', 'info');\r\n        },\r\n\r\n        \/* \u2500\u2500\u2500 TOGGLE CODE BLOCK \u2500\u2500\u2500 *\/\r\n        toggleCode: function (id, btn) {\r\n            var el = document.getElementById(id);\r\n            if (!el) return;\r\n            var visible = el.style.display === 'block';\r\n            el.style.display = visible ? 'none' : 'block';\r\n            if (btn) btn.textContent = visible ? 'Show Code' : 'Hide Code';\r\n        },\r\n\r\n        \/* \u2500\u2500\u2500 COPY CODE \u2500\u2500\u2500 *\/\r\n        copyCode: function (id) {\r\n            var el = document.getElementById(id);\r\n            if (!el || !el.textContent.trim()) { this.showToast('Nothing to copy!', 'error'); return; }\r\n            navigator.clipboard.writeText(el.textContent).then(function () {}).catch(function () {});\r\n            this.showToast('Copied!', 'success');\r\n        },\r\n\r\n        \/* \u2500\u2500\u2500 SIMULATE \u2500\u2500\u2500 *\/\r\n        simulate: function (id) {\r\n            var el = document.getElementById(id);\r\n            if (!el || !el.textContent.trim()) { this.showToast('Run Convert first!', 'error'); return; }\r\n            window.open('https:\/\/digitaljs.tilk.eu\/?code=' + encodeURIComponent(el.textContent), '_blank', 'noopener');\r\n        },\r\n\r\n        \/* \u2500\u2500\u2500 COPY TRUTH TABLE CSV \u2500\u2500\u2500 *\/\r\n        copyTruthTableCSV: function () {\r\n            var r = this.currentResult;\r\n            if (!r || !r.truthRows) { this.showToast('No truth table available!', 'error'); return; }\r\n            var csv = r.vars.join(',') + ',F\\n';\r\n            for (var i = 0; i < r.truthRows.length; i++) {\r\n                csv += r.truthRows[i].inputs.join(',') + ',' + r.truthRows[i].output + '\\n';\r\n            }\r\n            navigator.clipboard.writeText(csv).then(function () {}).catch(function () {});\r\n            this.showToast('CSV copied!', 'success');\r\n        },\r\n\r\n        \/* \u2500\u2500\u2500 SHOW TOAST \u2500\u2500\u2500 *\/\r\n        showToast: function (msg, type) {\r\n            var container = document.getElementById('pth-logic-gate-toast');\r\n            if (!container) return;\r\n            var toast = document.createElement('div');\r\n            toast.style.cssText = 'padding:12px 20px;border-radius:10px;font-size:14px;font-weight:600;color:#fff;pointer-events:auto;box-shadow:0 4px 15px rgba(0,0,0,.15);font-family:Inter,system-ui,sans-serif;';\r\n            var bg = type === 'success' ? '#059669' : type === 'error' ? '#dc2626' : '#2563eb';\r\n            toast.style.background = bg;\r\n            toast.textContent = msg;\r\n            container.appendChild(toast);\r\n            setTimeout(function () { if (toast.parentNode) toast.parentNode.removeChild(toast); }, 3000);\r\n        },\r\n\r\n        \/* \u2500\u2500\u2500 HISTORY \u2500\u2500\u2500 *\/\r\n        saveHistory: function (expr, vars) {\r\n            var hist = this.getHistory();\r\n            var entry = { expr: expr, vars: vars, ts: Date.now() };\r\n            \/* Remove duplicate if exists *\/\r\n            hist = hist.filter(function (h) { return h.expr !== expr; });\r\n            hist.unshift(entry);\r\n            if (hist.length > 8) hist = hist.slice(0, 8);\r\n            try { localStorage.setItem(this.historyKey, JSON.stringify(hist)); } catch (e) {}\r\n            this.renderHistory(hist);\r\n        },\r\n\r\n        getHistory: function () {\r\n            try { return JSON.parse(localStorage.getItem(this.historyKey) || '[]'); } catch (e) { return []; }\r\n        },\r\n\r\n        loadHistory: function () {\r\n            this.renderHistory(this.getHistory());\r\n        },\r\n\r\n        clearHistory: function () {\r\n            try { localStorage.removeItem(this.historyKey); } catch (e) {}\r\n            this.renderHistory([]);\r\n            this.showToast('History cleared!', 'info');\r\n        },\r\n\r\n        renderHistory: function (hist) {\r\n            var self = this;\r\n            var container = document.getElementById('pth-history-container');\r\n            if (!container) return;\r\n            if (!hist.length) {\r\n                container.innerHTML = '<div class=\"pth-history-empty\">No conversions yet.<br>Run an analysis to see history.<\/div>';\r\n                return;\r\n            }\r\n            var html = '';\r\n            for (var i = 0; i < hist.length; i++) {\r\n                var h = hist[i];\r\n                var d = new Date(h.ts);\r\n                var tStr = d.getHours() + ':' + String(d.getMinutes()).padStart(2, '0');\r\n                html += '<div class=\"pth-history-item\" data-expr=\"' + h.expr.replace(\/\"\/g, '&quot;') + '\">';\r\n                html += '<div class=\"pth-history-expr\">' + h.expr + '<\/div>';\r\n                html += '<div class=\"pth-history-meta\">Vars: ' + (h.vars || '') + ' \u00a0\u00b7\u00a0 ' + tStr + '<\/div>';\r\n                html += '<\/div>';\r\n            }\r\n            container.innerHTML = html;\r\n            var items = container.querySelectorAll('.pth-history-item');\r\n            for (var j = 0; j < items.length; j++) {\r\n                (function (item) {\r\n                    item.addEventListener('click', function () {\r\n                        var expr = item.getAttribute('data-expr');\r\n                        document.getElementById('pth-formula-input').value = expr;\r\n                        self.updateVars();\r\n                        self.process();\r\n                    });\r\n                })(items[j]);\r\n            }\r\n        },\r\n\r\n        \/* =====================================================\r\n           PARSER ENGINE\r\n           ===================================================== *\/\r\n        tokenize: function (str) {\r\n            var s = str.toUpperCase()\r\n                .replace(\/\\(\/g, ' ( ')\r\n                .replace(\/\\)\/g, ' ) ')\r\n                .replace(\/\\bXNOR\\b\/g, ' XNOR ')\r\n                .replace(\/\\bXOR\\b\/g, ' XOR ')\r\n                .replace(\/\\bNAND\\b\/g, ' NAND ')\r\n                .replace(\/\\bNOR\\b\/g, ' NOR ')\r\n                .replace(\/\\bIMPLIES\\b\/g, ' IMPLIES ')\r\n                .replace(\/->\/g, ' IMPLIES ')\r\n                .replace(\/=>\/g, ' IMPLIES ')\r\n                .replace(\/\\bNOT\\b\/g, ' NOT ')\r\n                .replace(\/\\bAND\\b\/g, ' AND ')\r\n                .replace(\/\\bOR\\b\/g, ' OR ');\r\n            return s.trim().split(\/\\s+\/).filter(function (t) { return t.length > 0; });\r\n        },\r\n\r\n        parseExpression: function (tokens) {\r\n            var outputQueue = [];\r\n            var operatorStack = [];\r\n            var precedence = { 'NOT': 5, 'NAND': 4, 'AND': 4, 'NOR': 3, 'OR': 3, 'XOR': 3, 'XNOR': 3, 'IMPLIES': 1 };\r\n            var ops = ['AND', 'OR', 'NOT', 'NAND', 'NOR', 'XOR', 'XNOR', 'IMPLIES'];\r\n\r\n            for (var i = 0; i < tokens.length; i++) {\r\n                var token = tokens[i];\r\n                if (!token) continue;\r\n                if (ops.indexOf(token) !== -1) {\r\n                    while (operatorStack.length > 0 &&\r\n                           operatorStack[operatorStack.length - 1] !== '(' &&\r\n                           precedence[operatorStack[operatorStack.length - 1]] >= precedence[token] &&\r\n                           token !== 'NOT') {\r\n                        outputQueue.push(operatorStack.pop());\r\n                    }\r\n                    operatorStack.push(token);\r\n                } else if (token === '(') {\r\n                    operatorStack.push(token);\r\n                } else if (token === ')') {\r\n                    while (operatorStack.length > 0 && operatorStack[operatorStack.length - 1] !== '(') {\r\n                        outputQueue.push(operatorStack.pop());\r\n                    }\r\n                    if (operatorStack.length === 0) throw new Error('Mismatched parentheses');\r\n                    operatorStack.pop();\r\n                } else {\r\n                    outputQueue.push({ type: 'LITERAL', value: token });\r\n                }\r\n            }\r\n            while (operatorStack.length > 0) {\r\n                var op = operatorStack.pop();\r\n                if (op === '(') throw new Error('Mismatched parentheses');\r\n                outputQueue.push(op);\r\n            }\r\n\r\n            var stack = [];\r\n            for (var j = 0; j < outputQueue.length; j++) {\r\n                var item = outputQueue[j];\r\n                if (typeof item === 'string') {\r\n                    if (item === 'NOT') {\r\n                        if (stack.length < 1) throw new Error('Invalid NOT syntax');\r\n                        stack.push({ type: 'OP', op: 'NOT', left: stack.pop() });\r\n                    } else {\r\n                        if (stack.length < 2) throw new Error('Invalid syntax near ' + item);\r\n                        var right = stack.pop(); var left = stack.pop();\r\n                        stack.push({ type: 'OP', op: item, left: left, right: right });\r\n                    }\r\n                } else { stack.push(item); }\r\n            }\r\n            if (stack.length !== 1) throw new Error('Invalid logical structure');\r\n            return stack[0];\r\n        },\r\n\r\n        \/* \u2500\u2500\u2500 AST EVALUATOR \u2500\u2500\u2500 *\/\r\n        evalAST: function (node, assignment) {\r\n            if (!node) return 0;\r\n            if (node.type === 'LITERAL') {\r\n                if (node.value === '1') return 1;\r\n                if (node.value === '0') return 0;\r\n                return assignment[node.value] !== undefined ? assignment[node.value] : 0;\r\n            }\r\n            var L = this.evalAST(node.left, assignment);\r\n            var R = node.right ? this.evalAST(node.right, assignment) : 0;\r\n            switch (node.op) {\r\n                case 'NOT':     return L ? 0 : 1;\r\n                case 'AND':     return (L && R) ? 1 : 0;\r\n                case 'OR':      return (L || R) ? 1 : 0;\r\n                case 'NAND':    return (L && R) ? 0 : 1;\r\n                case 'NOR':     return (L || R) ? 0 : 1;\r\n                case 'XOR':     return (L !== R) ? 1 : 0;\r\n                case 'XNOR':    return (L === R) ? 1 : 0;\r\n                case 'IMPLIES': return (!L || R) ? 1 : 0;\r\n                default:        return 0;\r\n            }\r\n        },\r\n\r\n        \/* \u2500\u2500\u2500 UNIVERSAL CONVERTER \u2500\u2500\u2500 *\/\r\n        convertAST: function (node, mode) {\r\n            if (!node) return '';\r\n            if (node.type === 'LITERAL') {\r\n                var v = node.value;\r\n                if (v === '1') return mode === 'NAND' ? 'A NAND (A NAND A)' : '(A NOR (A NOR A)) NOR (A NOR (A NOR A))';\r\n                if (v === '0') return mode === 'NAND' ? '(A NAND (A NAND A)) NAND (A NAND (A NAND A))' : 'A NOR (A NOR A)';\r\n                return v;\r\n            }\r\n            var L = this.convertAST(node.left, mode);\r\n            var R = node.right ? this.convertAST(node.right, mode) : null;\r\n            var wL = '(' + L + ')';\r\n            var wR = R ? '(' + R + ')' : '';\r\n\r\n            if (mode === 'NAND') {\r\n                switch (node.op) {\r\n                    case 'NOT':     return wL + ' NAND ' + wL;\r\n                    case 'AND':     return '(' + wL + ' NAND ' + wR + ') NAND (' + wL + ' NAND ' + wR + ')';\r\n                    case 'OR':      return '(' + wL + ' NAND ' + wL + ') NAND (' + wR + ' NAND ' + wR + ')';\r\n                    case 'NAND':    return wL + ' NAND ' + wR;\r\n                    case 'NOR':     return '((' + wL + ' NAND ' + wL + ') NAND (' + wR + ' NAND ' + wR + ')) NAND ((' + wL + ' NAND ' + wL + ') NAND (' + wR + ' NAND ' + wR + '))';\r\n                    case 'XOR': {\r\n                        var xn = '(' + wL + ' NAND ' + wR + ')';\r\n                        return '(' + wL + ' NAND ' + xn + ') NAND (' + wR + ' NAND ' + xn + ')';\r\n                    }\r\n                    case 'XNOR': {\r\n                        var xnorN = '(' + wL + ' NAND ' + wR + ')';\r\n                        var xorE = '(' + wL + ' NAND ' + xnorN + ') NAND (' + wR + ' NAND ' + xnorN + ')';\r\n                        return '(' + xorE + ') NAND (' + xorE + ')';\r\n                    }\r\n                    case 'IMPLIES': return wL + ' NAND (' + wR + ' NAND ' + wR + ')';\r\n                }\r\n            } else if (mode === 'NOR') {\r\n                switch (node.op) {\r\n                    case 'NOT':     return wL + ' NOR ' + wL;\r\n                    case 'OR':      return '(' + wL + ' NOR ' + wR + ') NOR (' + wL + ' NOR ' + wR + ')';\r\n                    case 'AND':     return '(' + wL + ' NOR ' + wL + ') NOR (' + wR + ' NOR ' + wR + ')';\r\n                    case 'NOR':     return wL + ' NOR ' + wR;\r\n                    case 'NAND':    return '((' + wL + ' NOR ' + wL + ') NOR (' + wR + ' NOR ' + wR + ')) NOR ((' + wL + ' NOR ' + wL + ') NOR (' + wR + ' NOR ' + wR + '))';\r\n                    case 'XOR': {\r\n                        var xnL = '(' + wL + ' NOR ' + wL + ')';\r\n                        var xnR = '(' + wR + ' NOR ' + wR + ')';\r\n                        var xna = '(' + xnL + ' NOR ' + wR + ')';\r\n                        var xnb = '(' + xnR + ' NOR ' + wL + ')';\r\n                        return '(' + xna + ' NOR ' + xna + ') NOR (' + xnb + ' NOR ' + xnb + ')';\r\n                    }\r\n                    case 'XNOR': {\r\n                        var xnorL = '(' + wL + ' NOR ' + wL + ')';\r\n                        var xnorR = '(' + wR + ' NOR ' + wR + ')';\r\n                        var xorA = '(' + xnorL + ' NOR ' + wR + ')';\r\n                        var xorB = '(' + xnorR + ' NOR ' + wL + ')';\r\n                        var xorFull = '((' + xorA + ' NOR ' + xorA + ') NOR (' + xorB + ' NOR ' + xorB + '))';\r\n                        return xorFull + ' NOR ' + xorFull;\r\n                    }\r\n                    case 'IMPLIES': {\r\n                        var notA = '(' + wL + ' NOR ' + wL + ')';\r\n                        return '(' + notA + ' NOR ' + wR + ') NOR (' + notA + ' NOR ' + wR + ')';\r\n                    }\r\n                }\r\n            }\r\n            return '(' + L + ' ' + node.op + ' ' + R + ')';\r\n        },\r\n\r\n        robustConvert: function (formula, mode) {\r\n            try {\r\n                var tokens = this.tokenize(formula);\r\n                var ast = this.parseExpression(tokens);\r\n                return this.convertAST(ast, mode);\r\n            } catch (e) { return 'Parsing error: ' + e.message; }\r\n        },\r\n\r\n        \/* \u2500\u2500\u2500 SIMPLIFIER \u2500\u2500\u2500 *\/\r\n        simplifyFormula: function (formula) {\r\n            var curr = formula.replace(\/\\s+\/g, ' ').trim();\r\n            var stepsHTML = '';\r\n            var iter = 0;\r\n\r\n            var addLog = function (oldF, newF, rule, details) {\r\n                iter++;\r\n                stepsHTML += '<div class=\"pth-step-row\"><strong>Step ' + iter + ':<\/strong> Applied <em>' + rule + '<\/em><span class=\"pth-step-logic\">' + oldF + ' \u2192 <strong>' + newF + '<\/strong><\/span><span style=\"color:#b45309;font-size:12px;\">' + details + '<\/span><\/div>';\r\n            };\r\n\r\n            var changed = true;\r\n            while (changed && iter < 20) {\r\n                var prev = curr;\r\n\r\n                if (\/\\bIMPLIES\\b\/.test(curr)) {\r\n                    curr = curr.replace(\/(\\(.+?\\)|\\w+)\\s+IMPLIES\\s+(\\(.+?\\)|\\w+)\/g, 'NOT $1 OR $2');\r\n                    if (curr !== prev) { addLog(prev, curr, 'Implication Elimination', 'A \\u2192 B becomes NOT A OR B.'); continue; }\r\n                }\r\n                if (\/\\bNOT\\s+NOT\\b\/.test(curr)) {\r\n                    curr = curr.replace(\/NOT\\s+NOT\\s*(\\(.+?\\)|\\w+)\/, '$1');\r\n                    if (curr !== prev) { addLog(prev, curr, 'Double Negation', 'NOT NOT X = X.'); continue; }\r\n                }\r\n                if (\/AND\\s+1|1\\s+AND\/.test(curr)) {\r\n                    curr = curr.replace(\/(\\(.+?\\)|\\w+)\\s+AND\\s+1\/, '$1').replace(\/1\\s+AND\\s+(\\(.+?\\)|\\w+)\/, '$1');\r\n                    if (curr !== prev) { addLog(prev, curr, 'Identity Law (AND)', 'X AND 1 = X.'); continue; }\r\n                }\r\n                if (\/AND\\s+0|0\\s+AND\/.test(curr)) {\r\n                    curr = curr.replace(\/(\\(.+?\\)|\\w+)\\s+AND\\s+0\/, '0').replace(\/0\\s+AND\\s+(\\(.+?\\)|\\w+)\/, '0');\r\n                    if (curr !== prev) { addLog(prev, curr, 'Null Law (AND)', 'X AND 0 = 0.'); continue; }\r\n                }\r\n                if (\/OR\\s+0|0\\s+OR\/.test(curr)) {\r\n                    curr = curr.replace(\/(\\(.+?\\)|\\w+)\\s+OR\\s+0\/, '$1').replace(\/0\\s+OR\\s+(\\(.+?\\)|\\w+)\/, '$1');\r\n                    if (curr !== prev) { addLog(prev, curr, 'Identity Law (OR)', 'X OR 0 = X.'); continue; }\r\n                }\r\n                if (\/OR\\s+1|1\\s+OR\/.test(curr)) {\r\n                    curr = curr.replace(\/.+\\s+OR\\s+1\/, '1').replace(\/1\\s+OR\\s+.+\/, '1');\r\n                    if (curr !== prev) { addLog(prev, curr, 'Null Law (OR)', 'X OR 1 = 1.'); continue; }\r\n                }\r\n\r\n                \/* Idempotent *\/\r\n                var parts = curr.split(\/\\s+(AND|OR)\\s+\/);\r\n                if (parts.length === 3 && parts[0].trim() === parts[2].trim()) {\r\n                    curr = parts[0];\r\n                    addLog(prev, curr, 'Idempotent Law', parts[1] + 'ing a value with itself yields itself.'); continue;\r\n                }\r\n\r\n                \/* Strip outer parens *\/\r\n                if (curr.startsWith('(') && curr.endsWith(')')) {\r\n                    var inner = curr.substring(1, curr.length - 1);\r\n                    var count = 0; var valid = true;\r\n                    for (var ci = 0; ci < inner.length; ci++) {\r\n                        if (inner[ci] === '(') count++;\r\n                        if (inner[ci] === ')') count--;\r\n                        if (count < 0) { valid = false; break; }\r\n                    }\r\n                    if (valid && count === 0) { curr = inner; continue; }\r\n                }\r\n\r\n                changed = false;\r\n            }\r\n            if (iter === 0) stepsHTML = '<div style=\"color:#92400e;font-size:14px;\">Expression is already in simplified form.<\/div>';\r\n            return { result: curr, log: stepsHTML };\r\n        },\r\n\r\n        \/* \u2500\u2500\u2500 VERILOG GENERATOR \u2500\u2500\u2500 *\/\r\n        generateVerilog: function (formula, mode, vars) {\r\n            var moduleName = 'pth_logic_' + (mode || 'original');\r\n            var inputPorts = vars.length > 0 ? vars.map(function (v) { return '    input ' + v + ','; }).join('\\n') : '    input dummy,';\r\n            var expr = formula;\r\n            if (expr === '1') expr = \"1'b1\";\r\n            else if (expr === '0') expr = \"1'b0\";\r\n            else {\r\n                if (mode === 'NAND') { expr = expr.replace(\/NAND\/g, '~&'); }\r\n                if (mode === 'NOR') { expr = expr.replace(\/NOR\/g, '~|'); }\r\n                expr = expr.replace(\/\\bAND\\b\/g, '&').replace(\/\\bOR\\b\/g, '|')\r\n                           .replace(\/\\bNOT\\s*\/g, '~').replace(\/\\bXOR\\b\/g, '^')\r\n                           .replace(\/\\bXNOR\\b\/g, '~^');\r\n            }\r\n            return 'module ' + moduleName + '(\\n' + inputPorts + '\\n    output F\\n);\\n\\n    \/\/ Generated from: ' + formula + '\\n    assign F = ' + expr + ';\\n\\nendmodule';\r\n        },\r\n\r\n        \/* \u2500\u2500\u2500 VHDL GENERATOR \u2500\u2500\u2500 *\/\r\n        generateVHDL: function (formula, mode, vars) {\r\n            var entityName = 'pth_logic_' + (mode || 'original');\r\n            var portLines = vars.length > 0\r\n                ? vars.map(function (v) { return '        ' + v + ' : in  STD_LOGIC;'; }).join('\\n')\r\n                : '        dummy : in  STD_LOGIC;';\r\n            var expr = formula;\r\n            if (expr === '1') expr = \"'1'\";\r\n            else if (expr === '0') expr = \"'0'\";\r\n            else {\r\n                if (mode === 'NAND') { expr = expr.replace(\/\\bNAND\\b\/g, 'nand'); }\r\n                if (mode === 'NOR')  { expr = expr.replace(\/\\bNOR\\b\/g,  'nor'); }\r\n                expr = expr.replace(\/\\bAND\\b\/g, 'and').replace(\/\\bOR\\b\/g, 'or')\r\n                           .replace(\/\\bNOT\\b\\s*\/g, 'not ').replace(\/\\bXOR\\b\/g, 'xor')\r\n                           .replace(\/\\bXNOR\\b\/g, 'xnor');\r\n            }\r\n            return 'library IEEE;\\nuse IEEE.STD_LOGIC_1164.ALL;\\n\\nentity ' + entityName + ' is\\n    port (\\n' + portLines + '\\n        F : out STD_LOGIC\\n    );\\nend entity ' + entityName + ';\\n\\narchitecture behavioral of ' + entityName + ' is\\nbegin\\n    -- Generated from: ' + formula + '\\n    F <= ' + expr + ';\\nend architecture behavioral;';\r\n        },\r\n\r\n        \/* \u2500\u2500\u2500 GATE COUNTER \u2500\u2500\u2500 *\/\r\n        countGates: function (expr, gateType) {\r\n            var re = new RegExp('\\\\b' + gateType + '\\\\b', 'g');\r\n            var matches = expr.match(re);\r\n            return matches ? matches.length : 0;\r\n        },\r\n\r\n        analyzeGates: function (expr, mode) {\r\n            var total = this.countGates(expr, mode);\r\n            var notCount = this.countGates(expr, 'NOT');\r\n            var parenDepth = 0; var maxDepth = 0;\r\n            for (var i = 0; i < expr.length; i++) {\r\n                if (expr[i] === '(') { parenDepth++; if (parenDepth > maxDepth) maxDepth = parenDepth; }\r\n                if (expr[i] === ')') parenDepth--;\r\n            }\r\n            return { total: total, depth: maxDepth, notImplied: notCount };\r\n        },\r\n\r\n        \/* \u2500\u2500\u2500 TRUTH TABLE \u2500\u2500\u2500 *\/\r\n        buildTruthTable: function (ast, vars) {\r\n            var self = this;\r\n            var rows = [];\r\n            var n = vars.length;\r\n            if (n > 6) return null; \/* Safety cap *\/\r\n            var count = Math.pow(2, n);\r\n            for (var i = 0; i < count; i++) {\r\n                var assignment = {};\r\n                var inputs = [];\r\n                for (var j = 0; j < n; j++) {\r\n                    var bit = (i >> (n - 1 - j)) & 1;\r\n                    assignment[vars[j]] = bit;\r\n                    inputs.push(bit);\r\n                }\r\n                var out;\r\n                try { out = self.evalAST(ast, assignment); } catch (e) { out = 'X'; }\r\n                rows.push({ inputs: inputs, output: out });\r\n            }\r\n            return rows;\r\n        },\r\n\r\n        renderTruthTable: function (rows, vars) {\r\n            if (!rows) {\r\n                document.getElementById('pth-truth-table-container').innerHTML =\r\n                    '<div class=\"pth-info-row\">\\u26a0\\ufe0f Truth table limited to \\u2264\\ufe0f 6 variables (max 64 rows).<\/div>';\r\n                return;\r\n            }\r\n            var html = '<table class=\"pth-truth-table\" aria-label=\"Boolean expression truth table\"><thead><tr>';\r\n            for (var v = 0; v < vars.length; v++) html += '<th scope=\"col\">' + vars[v] + '<\/th>';\r\n            html += '<th scope=\"col\" style=\"background:#1d4ed8;\">F (Output)<\/th><\/tr><\/thead><tbody>';\r\n            var ones = 0, zeros = 0;\r\n            for (var r = 0; r < rows.length; r++) {\r\n                html += '<tr>';\r\n                for (var i = 0; i < rows[r].inputs.length; i++) html += '<td>' + rows[r].inputs[i] + '<\/td>';\r\n                var out = rows[r].output;\r\n                var cls = out === 1 ? 'pth-out-1' : out === 0 ? 'pth-out-0' : 'pth-out-x';\r\n                if (out === 1) ones++; else if (out === 0) zeros++;\r\n                html += '<td class=\"' + cls + '\">' + out + '<\/td><\/tr>';\r\n            }\r\n            html += '<\/tbody><\/table>';\r\n            document.getElementById('pth-truth-table-container').innerHTML = html;\r\n            document.getElementById('pth-tt-summary').innerHTML =\r\n                '<span class=\"pth-tt-chip pth-tt-chip-on\">\\u2713 ' + ones + ' rows output 1<\/span>' +\r\n                '<span class=\"pth-tt-chip pth-tt-chip-off\">\\u2715 ' + zeros + ' rows output 0<\/span>' +\r\n                '<span style=\"font-size:12px;color:#334155;font-weight:600;\">Total: ' + rows.length + ' combinations<\/span>';\r\n        },\r\n\r\n        \/* \u2500\u2500\u2500 K-MAP \u2500\u2500\u2500 *\/\r\n        renderKMap: function (rows, vars) {\r\n            var container = document.getElementById('pth-kmap-container');\r\n            var n = vars.length;\r\n\r\n            if (n < 2 || n > 4) {\r\n                container.innerHTML = '<div class=\"pth-kmap-note\">K-Map available for 2\\u20134 variables. Current: ' + n + ' variable' + (n !== 1 ? 's' : '') + '.<\/div>';\r\n                return;\r\n            }\r\n\r\n            \/* Build output lookup *\/\r\n            var lookup = {};\r\n            for (var r = 0; r < rows.length; r++) {\r\n                lookup[rows[r].inputs.join('')] = rows[r].output;\r\n            }\r\n\r\n            \/* Gray code orders *\/\r\n            var gray2 = ['00', '01', '11', '10'];\r\n            var gray4 = ['0000', '0001', '0011', '0010', '0100', '0101', '0111', '0110',\r\n                         '1100', '1101', '1111', '1110', '1000', '1001', '1011', '1010'];\r\n\r\n            var html = '<div class=\"pth-kmap-title\">';\r\n            html += n + '-variable Karnaugh Map (' + vars.join(', ') + ')';\r\n            html += '<\/div>';\r\n\r\n            if (n === 2) {\r\n                \/* 2-var: rows = A (0,1), cols = B (00=0,01=1,10=11 gray) *\/\r\n                var colHdr = ['B=0', 'B=1'];\r\n                var rowHdr = ['A=0', 'A=1'];\r\n                html += '<table class=\"pth-kmap-table\" aria-label=\"2-variable K-Map\">';\r\n                html += '<tr><th class=\"pth-kmap-corner\">' + vars[0] + '\\\\' + vars[1] + '<\/th>';\r\n                for (var cj = 0; cj < 2; cj++) html += '<th>' + colHdr[cj] + '<\/th>';\r\n                html += '<\/tr>';\r\n                for (var ai = 0; ai < 2; ai++) {\r\n                    html += '<tr><th>' + rowHdr[ai] + '<\/th>';\r\n                    for (var bi = 0; bi < 2; bi++) {\r\n                        var key = '' + ai + bi;\r\n                        var val = lookup[key] !== undefined ? lookup[key] : 'X';\r\n                        var cls = val === 1 ? 'pth-kmap-1' : val === 0 ? 'pth-kmap-0' : 'pth-kmap-x';\r\n                        html += '<td class=\"' + cls + '\" title=\"' + vars[0] + '=' + ai + ', ' + vars[1] + '=' + bi + '\">' + val + '<\/td>';\r\n                    }\r\n                    html += '<\/tr>';\r\n                }\r\n                html += '<\/table>';\r\n            } else if (n === 3) {\r\n                \/* 3-var: rows = A (0,1), cols = BC in gray *\/\r\n                var bcGray = ['00', '01', '11', '10'];\r\n                html += '<table class=\"pth-kmap-table\" aria-label=\"3-variable K-Map\">';\r\n                html += '<tr><th class=\"pth-kmap-corner\">' + vars[0] + '\\\\ ' + vars[1] + vars[2] + '<\/th>';\r\n                for (var gi = 0; gi < 4; gi++) html += '<th>' + bcGray[gi] + '<\/th>';\r\n                html += '<\/tr>';\r\n                for (var ar = 0; ar < 2; ar++) {\r\n                    html += '<tr><th>' + ar + '<\/th>';\r\n                    for (var gc = 0; gc < 4; gc++) {\r\n                        var kkey = '' + ar + bcGray[gc];\r\n                        var kval = lookup[kkey] !== undefined ? lookup[kkey] : 'X';\r\n                        var kcls = kval === 1 ? 'pth-kmap-1' : kval === 0 ? 'pth-kmap-0' : 'pth-kmap-x';\r\n                        html += '<td class=\"' + kcls + '\">' + kval + '<\/td>';\r\n                    }\r\n                    html += '<\/tr>';\r\n                }\r\n                html += '<\/table>';\r\n            } else if (n === 4) {\r\n                \/* 4-var: rows = AB gray, cols = CD gray *\/\r\n                var abGray = ['00', '01', '11', '10'];\r\n                var cdGray = ['00', '01', '11', '10'];\r\n                html += '<table class=\"pth-kmap-table\" aria-label=\"4-variable K-Map\">';\r\n                html += '<tr><th class=\"pth-kmap-corner\">' + vars[0] + vars[1] + '\\\\' + vars[2] + vars[3] + '<\/th>';\r\n                for (var ci = 0; ci < 4; ci++) html += '<th>' + cdGray[ci] + '<\/th>';\r\n                html += '<\/tr>';\r\n                for (var ri = 0; ri < 4; ri++) {\r\n                    html += '<tr><th>' + abGray[ri] + '<\/th>';\r\n                    for (var ci2 = 0; ci2 < 4; ci2++) {\r\n                        var mkey = abGray[ri] + cdGray[ci2];\r\n                        var mval = lookup[mkey] !== undefined ? lookup[mkey] : 'X';\r\n                        var mcls = mval === 1 ? 'pth-kmap-1' : mval === 0 ? 'pth-kmap-0' : 'pth-kmap-x';\r\n                        html += '<td class=\"' + mcls + '\">' + mval + '<\/td>';\r\n                    }\r\n                    html += '<\/tr>';\r\n                }\r\n                html += '<\/table>';\r\n            }\r\n            html += '<p class=\"pth-kmap-note\">\\ud83d\\udca1 Gray code ordering ensures adjacent cells differ by one variable. 1\\x3D green, 0\\x3D red.<\/p>';\r\n            container.innerHTML = html;\r\n        },\r\n\r\n        \/* \u2500\u2500\u2500 GATE COUNT RENDER \u2500\u2500\u2500 *\/\r\n        renderGateCount: function (nandExpr, norExpr) {\r\n            var self = this;\r\n            var nandA = self.analyzeGates(nandExpr, 'NAND');\r\n            var norA = self.analyzeGates(norExpr, 'NOR');\r\n\r\n            var colors = { NAND: '#8b5cf6', NOR: '#ea580c' };\r\n\r\n            function buildGrid(a, gateLabel) {\r\n                return '<div class=\"pth-gate-chip\"><div class=\"pth-gate-chip-label\">' + gateLabel + ' gates<\/div><div class=\"pth-gate-chip-val\" style=\"color:' + (gateLabel === 'NAND' ? '#5b21b6' : '#c2410c') + '\">' + a.total + '<\/div><div class=\"pth-gate-chip-sub\">universal gates<\/div><\/div>' +\r\n                    '<div class=\"pth-gate-chip\"><div class=\"pth-gate-chip-label\">Logic depth<\/div><div class=\"pth-gate-chip-val\">' + a.depth + '<\/div><div class=\"pth-gate-chip-sub\">nesting levels<\/div><\/div>';\r\n            }\r\n\r\n            document.getElementById('pth-nand-count-grid').innerHTML = buildGrid(nandA, 'NAND');\r\n            document.getElementById('pth-nor-count-grid').innerHTML = buildGrid(norA, 'NOR');\r\n\r\n            var maxVal = Math.max(nandA.total, norA.total, 1);\r\n\r\n            function buildBars(a, gateType, color) {\r\n                return '<div class=\"pth-gate-bar-row\"><div class=\"pth-gate-bar-label\">' + gateType + '<\/div><div class=\"pth-gate-bar-track\"><div class=\"pth-gate-bar-fill\" style=\"width:' + Math.round((a.total \/ maxVal) * 100) + '%;background:' + color + ';\"><\/div><\/div><div class=\"pth-gate-bar-num\">' + a.total + '<\/div><\/div>';\r\n            }\r\n\r\n            document.getElementById('pth-nand-bar-wrap').innerHTML = buildBars(nandA, 'NAND', colors.NAND);\r\n            document.getElementById('pth-nor-bar-wrap').innerHTML = buildBars(norA, 'NOR', colors.NOR);\r\n\r\n            var verdict = '';\r\n            if (nandA.total < norA.total) {\r\n                verdict = '<div style=\"background:#f5f3ff;border:1px solid #ede9fe;color:#6d28d9;border-radius:8px;padding:12px 16px;font-size:14px;font-weight:700;\">\\ud83c\\udfc6 NAND implementation is more efficient (' + nandA.total + ' gates vs NOR\\u2019s ' + norA.total + ' gates).<\/div>';\r\n            } else if (norA.total < nandA.total) {\r\n                verdict = '<div style=\"background:#fff7ed;border:1px solid #fed7aa;color:#c2410c;border-radius:8px;padding:12px 16px;font-size:14px;font-weight:700;\">\\ud83c\\udfc6 NOR implementation is more efficient (' + norA.total + ' gates vs NAND\\u2019s ' + nandA.total + ' gates).<\/div>';\r\n            } else {\r\n                verdict = '<div style=\"background:#f8fafc;border:1px solid #e2e8f0;color:#475569;border-radius:8px;padding:12px 16px;font-size:14px;font-weight:700;\">\\u2696\\ufe0f Both implementations use equal gate count (' + nandA.total + ' gates each).<\/div>';\r\n            }\r\n            document.getElementById('pth-gate-verdict').innerHTML = verdict;\r\n        },\r\n\r\n        \/* \u2500\u2500\u2500 HIGHLIGHT GATES \u2500\u2500\u2500 *\/\r\n        highlightGates: function (str, type) {\r\n            var cls = type === 'NAND' ? 'pth-nand-text' : 'pth-nor-text';\r\n            var re = new RegExp('\\\\b' + type + '\\\\b', 'g');\r\n            return str.replace(re, '<span class=\"' + cls + '\">' + type + '<\/span>');\r\n        },\r\n\r\n        \/* \u2500\u2500\u2500 EXPORT ALL \u2500\u2500\u2500 *\/\r\n        exportAll: function () {\r\n            var r = this.currentResult;\r\n            if (!r) { this.showToast('Run Convert first!', 'error'); return; }\r\n            var txt = '\/\/ ===========================================\\n';\r\n            txt += '\/\/ PrimeToolHub \u2014 Universal Logic Gate Converter Pro v3.0\\n';\r\n            txt += '\/\/ Expression: ' + r.rawInput + '\\n';\r\n            txt += '\/\/ Simplified: ' + r.simplified + '\\n';\r\n            txt += '\/\/ Variables:  ' + r.vars.join(', ') + '\\n';\r\n            txt += '\/\/ ===========================================\\n\\n';\r\n            txt += '\/\/ --- Original Verilog ---\\n' + document.getElementById('pth-original-verilog').textContent + '\\n\\n';\r\n            txt += '\/\/ --- NAND Verilog ---\\n' + document.getElementById('pth-nand-verilog').textContent + '\\n\\n';\r\n            txt += '\/\/ --- NOR Verilog ---\\n' + document.getElementById('pth-nor-verilog').textContent + '\\n\\n';\r\n            txt += '\/\/ --- VHDL Original ---\\n' + document.getElementById('pth-orig-vhdl').textContent + '\\n\\n';\r\n            txt += '\/\/ --- VHDL Simplified ---\\n' + document.getElementById('pth-simp-vhdl').textContent + '\\n\\n';\r\n            txt += '\/\/ --- VHDL NAND ---\\n' + document.getElementById('pth-nand-vhdl').textContent + '\\n\\n';\r\n            txt += '\/\/ --- VHDL NOR ---\\n' + document.getElementById('pth-nor-vhdl').textContent + '\\n';\r\n            var blob = new Blob([txt], { type: 'text\/plain' });\r\n            var url = URL.createObjectURL(blob);\r\n            var a = document.createElement('a');\r\n            a.href = url; a.download = 'pth_logic_export.txt';\r\n            document.body.appendChild(a); a.click();\r\n            document.body.removeChild(a); URL.revokeObjectURL(url);\r\n            this.showToast('Exported!', 'success');\r\n        },\r\n\r\n        \/* \u2500\u2500\u2500 MAIN PROCESS \u2500\u2500\u2500 *\/\r\n        process: function () {\r\n            var self = this;\r\n            var rawInput = (document.getElementById('pth-formula-input').value || '').toUpperCase().trim();\r\n            var errBox = document.getElementById('pth-error-box');\r\n\r\n            if (!rawInput) {\r\n                errBox.textContent = 'Please enter a Boolean expression.';\r\n                errBox.style.display = 'block';\r\n                return;\r\n            }\r\n\r\n            try {\r\n                var tokens = self.tokenize(rawInput);\r\n                var ast = self.parseExpression(tokens);\r\n                errBox.style.display = 'none'; errBox.textContent = '';\r\n\r\n                var vars = self.updateVars();\r\n\r\n                \/* Simplify *\/\r\n                var simp = self.simplifyFormula(rawInput);\r\n                document.getElementById('pth-simplification-steps').innerHTML = simp.log;\r\n                document.getElementById('pth-simplified-display').textContent = simp.result;\r\n\r\n                \/* Conversions *\/\r\n                var rawNand = self.robustConvert(rawInput, 'NAND');\r\n                var rawNor  = self.robustConvert(rawInput, 'NOR');\r\n                var optNand = self.robustConvert(simp.result, 'NAND');\r\n                var optNor  = self.robustConvert(simp.result, 'NOR');\r\n\r\n                \/* NAND display *\/\r\n                document.getElementById('pth-nand-display').innerHTML = self.highlightGates(optNand, 'NAND');\r\n                document.getElementById('pth-nand-verilog').textContent = self.generateVerilog(optNand, 'NAND', vars);\r\n\r\n                \/* NOR display *\/\r\n                document.getElementById('pth-nor-display').innerHTML = self.highlightGates(optNor, 'NOR');\r\n                document.getElementById('pth-nor-verilog').textContent = self.generateVerilog(optNor, 'NOR', vars);\r\n\r\n                \/* Verilog raw *\/\r\n                document.getElementById('pth-original-verilog').textContent = self.generateVerilog(rawInput, null, vars);\r\n                document.getElementById('pth-raw-nand').innerHTML = self.highlightGates(rawNand, 'NAND');\r\n                document.getElementById('pth-raw-nor').innerHTML  = self.highlightGates(rawNor,  'NOR');\r\n\r\n                \/* VHDL *\/\r\n                document.getElementById('pth-orig-vhdl').textContent = self.generateVHDL(rawInput, null, vars);\r\n                document.getElementById('pth-simp-vhdl').textContent = self.generateVHDL(simp.result, null, vars);\r\n                document.getElementById('pth-nand-vhdl').textContent = self.generateVHDL(optNand, 'NAND', vars);\r\n                document.getElementById('pth-nor-vhdl').textContent  = self.generateVHDL(optNor,  'NOR',  vars);\r\n\r\n                \/* Truth table *\/\r\n                var truthRows = self.buildTruthTable(ast, vars);\r\n                self.renderTruthTable(truthRows, vars);\r\n\r\n                \/* K-Map *\/\r\n                if (truthRows) self.renderKMap(truthRows, vars);\r\n\r\n                \/* Gate count *\/\r\n                self.renderGateCount(optNand, optNor);\r\n\r\n                \/* Store result *\/\r\n                self.currentResult = {\r\n                    rawInput: rawInput, simplified: simp.result,\r\n                    vars: vars, truthRows: truthRows\r\n                };\r\n\r\n                \/* History *\/\r\n                self.saveHistory(rawInput, vars.join(', '));\r\n\r\n                \/* Show results + switch to simplify tab *\/\r\n                document.getElementById('pth-results-area').style.display = 'block';\r\n                self.switchTab('simplify');\r\n                self.showToast('Converted successfully!', 'success');\r\n\r\n                \/* Scroll to results *\/\r\n                document.getElementById('pth-results-area').scrollIntoView({ behavior: 'smooth', block: 'start' });\r\n\r\n            } catch (e) {\r\n                errBox.textContent = 'Syntax Error: ' + e.message;\r\n                errBox.style.display = 'block';\r\n                document.getElementById('pth-results-area').style.display = 'none';\r\n            }\r\n        }\r\n    };\r\n\r\n    \/* \u2500\u2500\u2500 BOOTSTRAP \u2014 WP\/LiteSpeed safe \u2500\u2500\u2500 *\/\r\n    function runInit() {\r\n        if (!window.pthLogicGateApp.initialized &&\r\n            document.getElementById('pth-logic-gate-wrapper')) {\r\n            window.pthLogicGateApp.initialized = true;\r\n            window.pthLogicGateApp.init();\r\n        }\r\n    }\r\n\r\n    \/* Try immediately, then on DOM ready, then on load, then via MutationObserver *\/\r\n    runInit();\r\n    if (document.readyState === 'loading') {\r\n        document.addEventListener('DOMContentLoaded', runInit);\r\n    }\r\n    window.addEventListener('load', function () { setTimeout(runInit, 50); });\r\n\r\n    \/* Fallback: MutationObserver for Woody\/LiteSpeed deferred injection *\/\r\n    if (!window.pthLogicGateApp.initialized && typeof MutationObserver !== 'undefined') {\r\n        var pthObserver = new MutationObserver(function () {\r\n            if (document.getElementById('pth-logic-gate-wrapper')) {\r\n                pthObserver.disconnect();\r\n                runInit();\r\n            }\r\n        });\r\n        pthObserver.observe(document.body || document.documentElement, { childList: true, subtree: true });\r\n        \/* Safety: disconnect after 10 seconds *\/\r\n        setTimeout(function () { pthObserver.disconnect(); }, 10000);\r\n    }\r\n\r\n})();\r\n<\/script>\n\n\n\n<div id=\"start-seo-article\"><\/div>\n\n\n\n<style>\n.pth-feature-wrap {\n    display: grid;\n    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));\n    gap: 20px; margin-bottom: 30px;\n}\n.pth-feat-box {\n    border: 1px solid #e2e8f0; background: #ffffff;\n    padding: 24px; border-radius: 12px;\n    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.02);\n    transition: all 0.3s ease;\n}\n.pth-feat-box:hover {\n    border-color: #bfdbfe; transform: translateY(-3px);\n    box-shadow: 0 10px 15px -3px rgba(0,0,0,0.05);\n}\n.pth-feat-title {\n    font-size: 1.05rem; font-weight: 800; color: #0f172a;\n    margin-bottom: 10px; display: flex; align-items: center; gap: 10px;\n}\n.pth-feat-text { font-size: 0.9rem; color: #1e293b; line-height: 1.6; margin: 0; font-weight: 500; }\n.pth-steps-wrap {\n    border: 1px solid #e2e8f0; background: #ffffff;\n    padding: 40px 30px; border-radius: 16px;\n    text-align: center;\n    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.02);\n    margin-bottom: 40px;\n}\n.pth-steps-title {\n    font-size: 1.2rem; font-weight: 800; color: #0f172a;\n    text-transform: uppercase; margin-bottom: 35px; letter-spacing: 1px;\n}\n.pth-steps-grid {\n    display: grid;\n    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));\n    gap: 30px;\n}\n.pth-step-item { display: flex; flex-direction: column; align-items: center; }\n.pth-step-num {\n    width: 45px; height: 45px; background: #2563eb; color: #ffffff;\n    border-radius: 50%; display: flex; align-items: center;\n    justify-content: center; font-weight: 800; font-size: 1.2rem;\n    margin-bottom: 15px; box-shadow: 0 4px 10px rgba(37,99,235,0.3);\n}\n.pth-step-name { font-weight: 800; color: #0f172a; margin-bottom: 8px; font-size: 1rem; }\n.pth-step-desc { font-size: 0.9rem; color: #1e293b; line-height: 1.5; margin: 0; font-weight: 500; }\n<\/style>\n \n<div class=\"pth-feature-wrap\">\n    <div class=\"pth-feat-box\">\n        <div class=\"pth-feat-title\">\ud83d\udfe2 8-Tab Results Dashboard<\/div>\n        <p class=\"pth-feat-text\">Every conversion opens across eight dedicated tabs: Simplify, NAND, NOR, VHDL, Truth Table, K-Map, Gate Count, and Raw Data. Switch between views instantly without re-running the conversion \u2014 all results live in memory from one click of <strong>\u2728 Convert &amp; Analyze<\/strong>.<\/p>\n    <\/div>\n    <div class=\"pth-feat-box\">\n        <div class=\"pth-feat-title\">\ud83d\udd35 Verilog &amp; VHDL Code Generation<\/div>\n        <p class=\"pth-feat-text\">The tool produces synthesizable Verilog and VHDL for four variants in parallel: the original expression, the simplified form, and both NAND-only and NOR-only implementations. Each code block has its own <strong>Show Code<\/strong>, <strong>\ud83d\udccb Copy<\/strong>, and <strong>\u25b6 Simulate<\/strong> button that launches DigitalJS directly.<\/p>\n    <\/div>\n    <div class=\"pth-feat-box\">\n        <div class=\"pth-feat-title\">\ud83d\udfe3 Truth Table, K-Map &amp; Gate Count<\/div>\n        <p class=\"pth-feat-text\">For up to 6 variables, the \ud83d\udcca Truth Table tab enumerates all input combinations with color-coded outputs and a one-click CSV export. The \ud83d\uddc2\ufe0f K-Map tab renders Gray-coded 2-, 3-, and 4-variable Karnaugh maps. The \ud83d\udd22 Gate Count tab compares NAND vs NOR implementations with an animated bar chart and a verdict on which uses fewer gates.<\/p>\n    <\/div>\n<\/div>\n \n<div class=\"pth-steps-wrap\">\n    <div class=\"pth-steps-title\">How to Use the Universal Logic Gate Converter Pro<\/div>\n    <div class=\"pth-steps-grid\">\n        <div class=\"pth-step-item\">\n            <div class=\"pth-step-num\">1<\/div>\n            <div class=\"pth-step-name\">Type or Build Your Expression<\/div>\n            <p class=\"pth-step-desc\">Enter a Boolean expression like <strong>(A AND B) OR (NOT C AND D)<\/strong> directly in the input field, or tap operator and variable keys on the Logic Keyboard in the sidebar. Variables A\u2013F are detected automatically.<\/p>\n        <\/div>\n        <div class=\"pth-step-item\">\n            <div class=\"pth-step-num\">2<\/div>\n            <div class=\"pth-step-name\">Click Convert &amp; Analyze<\/div>\n            <p class=\"pth-step-desc\">Press <strong>\u2728 Convert &amp; Analyze<\/strong> or hit Enter. The engine simplifies the expression step-by-step, converts it to optimized NAND and NOR, generates Verilog and VHDL, builds the truth table, and renders the K-Map \u2014 all at once.<\/p>\n        <\/div>\n        <div class=\"pth-step-item\">\n            <div class=\"pth-step-num\">3<\/div>\n            <div class=\"pth-step-name\">Explore the Result Tabs<\/div>\n            <p class=\"pth-step-desc\">Navigate across the eight tabs. The <strong>\ud83d\udcd0 Simplify<\/strong> tab shows each Boolean law applied. <strong>\ud83d\udfe3 NAND<\/strong> and <strong>\ud83d\udfe0 NOR<\/strong> tabs show optimized gate expressions. <strong>\ud83d\udca0 VHDL<\/strong> gives four ready-to-synthesize code blocks. <strong>\ud83d\udd22 Gate Count<\/strong> reveals which implementation is more efficient.<\/p>\n        <\/div>\n        <div class=\"pth-step-item\">\n            <div class=\"pth-step-num\">4<\/div>\n            <div class=\"pth-step-name\">Export or Simulate<\/div>\n            <p class=\"pth-step-desc\">Copy any code block with <strong>\ud83d\udccb Copy<\/strong>, or click <strong>\u25b6 Simulate<\/strong> to open the circuit live in DigitalJS. Use <strong>\ud83d\udcbe Export All<\/strong> to download a single <code>.txt<\/code> file containing all Verilog and VHDL variants. Truth table rows export as CSV with one click.<\/p>\n        <\/div>\n    <\/div>\n<\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Last updated: June 2026<\/p>\n\n\n\n<h2 id=\"\ud83d\udd34-how-a-boolean-to-nand-nor-converter-actually-works\" class=\"wp-block-heading\"><strong>\ud83d\udd34 How a Boolean to NAND\/NOR Converter Actually Works<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Every digital circuit can be built from a single gate type. That is the core promise of NAND and NOR universality \u2014 proven mathematically by Henry Sheffer for NOR and extended to NAND through the work of Charles Sanders Peirce. In practice it means a chip fab can stock one transistor configuration and construct any logic function from it. The savings in fabrication complexity are real and measurable.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The challenge is translation. You have a Boolean expression \u2014 say, <code>(A AND B) OR (NOT C)<\/code> \u2014 and you need the equivalent circuit using only NAND gates. Doing this manually means applying De Morgan&#8217;s theorems, substituting each gate type one by one, then verifying equivalence with a truth table. For a three-variable expression that takes ten minutes. For a six-variable design with nested XOR and IMPLIES operators, it takes most of an afternoon and errors are common.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This tool handles the full translation in the browser. No server, no upload, no account. Type your expression, press <strong>\u2728 Convert &amp; Analyze<\/strong>, and the parser builds an abstract syntax tree from the tokenized input. It then walks the tree recursively, applying the correct NAND or NOR substitution at every node. AND, OR, NOT, XOR, XNOR, NAND, NOR, and IMPLIES are all supported with mathematically verified gate expansions.<\/p>\n\n\n\n<h3 id=\"\ud83d\udfe2-the-ast-parser-and-full-operator-support\" class=\"wp-block-heading\"><strong>\ud83d\udfe2 The AST Parser and Full Operator Support<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The engine tokenizes your input and runs a shunting-yard algorithm to produce postfix notation, then reconstructs a full abstract syntax tree. Operator precedence follows standard digital logic convention \u2014 NOT binds tightest, then NAND and AND, then NOR, OR, XOR, and XNOR, with IMPLIES at the lowest level. Parentheses override precedence exactly as expected.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">XNOR conversion required its own expansion path \u2014 a commonly broken case in simpler tools. The NAND expansion for <code>A XNOR B<\/code> works in three stages:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\ud83d\udd35 Compute the shared intermediary: <code>N = (A NAND B)<\/code><\/li>\n\n\n\n<li>\ud83d\udfe0 Build XOR from NAND: <code>XOR = (A NAND N) NAND (B NAND N)<\/code><\/li>\n\n\n\n<li>\ud83d\udfe3 Negate using NAND: <code>XNOR = XOR NAND XOR<\/code><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">IMPLIES (<code>A \u2192 B<\/code>) expands as <code>NOT A OR B<\/code> before NAND or NOR substitution is applied. The simplification engine runs up to 20 passes, applying identity, null, idempotent, and double negation laws in sequence, logging each reduction as a numbered step inside the <strong>\ud83d\udcd0 Simplify<\/strong> tab.<\/p>\n\n\n\n<h2 id=\"\ud83d\udfe1-truth-tables-karnaugh-maps-and-gate-count-analysis\" class=\"wp-block-heading\"><strong>\ud83d\udfe1 Truth Tables, Karnaugh Maps, and Gate Count Analysis<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The <strong>\ud83d\udcca Truth Table<\/strong> tab enumerates every input combination for up to six variables \u2014 that is up to 64 rows. The AST evaluator walks each row&#8217;s variable assignment and produces a 1 or 0 output. Green cells mark high outputs, red marks low. Export the entire table as CSV with one button click \u2014 useful for importing into a spreadsheet or feeding a Verilog testbench.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The <strong>\ud83d\uddc2\ufe0f K-Map<\/strong> tab renders Karnaugh maps for 2-, 3-, and 4-variable expressions. Gray code ordering is applied correctly throughout \u2014 adjacent cells differ by exactly one variable, which is the property that makes visual group identification possible. Each cell is color-coded: green for output 1, red for output 0. The map pulls data directly from the truth table evaluator, so it always stays in sync with your expression.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For a deeper look at why NAND and NOR achieve functional completeness, the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Functional_completeness\" target=\"_blank\" rel=\"noreferrer noopener\">Wikipedia article on functional completeness<\/a> explains the mathematical proof clearly. The <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Operators\/Bitwise_AND\" target=\"_blank\" rel=\"noreferrer noopener\">MDN reference on bitwise operators<\/a> is useful context for understanding how the truth table evaluator handles binary arithmetic internally.<\/p>\n\n\n\n<h3 id=\"\ud83d\udfe2-gate-count-comparison-nand-vs-nor\" class=\"wp-block-heading\"><strong>\ud83d\udfe2 Gate Count Comparison \u2014 NAND vs NOR<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The <strong>\ud83d\udd22 Gate Count<\/strong> tab counts how many universal gates each implementation uses and measures nesting depth as a proxy for logic depth. A bar chart scales both implementations side by side, and a verdict line tells you which is more efficient for your specific expression. This matters in real hardware \u2014 fewer gates means smaller die area, lower power consumption, and reduced propagation delay.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">NAND implementations tend to win for AND-heavy expressions because AND to NAND is a one-step substitution requiring no structural change. NOR implementations win for OR-heavy expressions for the same reason. The gate count result feeds directly into your choice of target technology \u2014 CMOS processes differ in whether they favor NAND or NOR gate structures at the transistor level.<\/p>\n\n\n\n<h2 id=\"\ud83d\udd34-vhdl-export-verilog-simulation-and-session-history\" class=\"wp-block-heading\"><strong>\ud83d\udd34 VHDL Export, Verilog Simulation, and Session History<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The <strong>\ud83d\udca0 VHDL<\/strong> tab produces four complete VHDL entities in parallel: the original expression, the simplified form, NAND-only, and NOR-only. Each follows IEEE.STD_LOGIC_1164 conventions with correct entity declaration, architecture block, port map, and concurrent signal assignment. Paste any variant directly into Vivado, Quartus Prime, ModelSim, or GHDL.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The Verilog output in the <strong>\ud83d\udfe3 NAND<\/strong> and <strong>\ud83d\udfe0 NOR<\/strong> tabs uses <code>assign<\/code> statements with correct operator mapping for each gate type. Click <strong>\u25b6 Simulate<\/strong> and the tool opens DigitalJS \u2014 a free browser-based Verilog simulator \u2014 with the code pre-loaded. You can watch gate-level signal propagation in real time without installing any software on your machine.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The sidebar keeps a session history of your last eight conversions in localStorage. Click any entry to instantly reload that expression and re-run the full analysis across all eight tabs. This is particularly useful when comparing multiple candidate expressions during a schematic review session \u2014 no retyping required.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you need step-by-step Karnaugh map grouping with SOP and POS output, try our <a href=\"https:\/\/schoolict.net\/tools\/boolean-expression-simplifier\/\">Boolean Logic Simplifier<\/a>. For a broader collection of offline engineering utilities \u2014 number base converters, IC finders, and more \u2014 the <a href=\"https:\/\/schoolict.net\/tools\/free-web-tools-directory-prime-tool-hub\/\">Free Web Tools Directory<\/a> has everything running entirely in the browser with no signup required.<\/p>\n\n\n\n<style>\n.pth-faq-section { margin-top: 50px; margin-bottom: 40px; font-family: inherit; }\n.pth-faq-header {\n    font-size: 1.8rem; font-weight: 800; color: #0f172a;\n    margin-bottom: 25px; border-bottom: 2px solid #e2e8f0;\n    padding-bottom: 10px; display: flex; align-items: center; gap: 10px;\n}\n.pth-faq-grid { display: grid; grid-template-columns: 100%; gap: 20px; }\n@media (min-width: 768px)  { .pth-faq-grid { grid-template-columns: repeat(2, 1fr); } }\n@media (min-width: 1024px) { .pth-faq-grid { grid-template-columns: repeat(3, 1fr); } }\n.pth-faq-card {\n    background: #f8fafc; padding: 24px; border-radius: 12px;\n    border: 1px solid #e2e8f0; transition: transform 0.2s ease; break-inside: avoid;\n}\n.pth-faq-card:hover { transform: translateY(-3px); box-shadow: 0 4px 12px rgba(0,0,0,0.05); }\n.pth-faq-q { color: #0f172a; font-size: 1rem; font-weight: 700; margin: 0 0 12px; line-height: 1.4; }\n.pth-faq-a { margin: 0; font-size: 0.95rem; color: #1e293b; line-height: 1.6; font-weight: 500; }\n<\/style>\n \n<div class=\"pth-faq-section\">\n    <div class=\"pth-faq-header\">\ud83e\udd14 Frequently Asked Questions<\/div>\n    <div class=\"pth-faq-grid\">\n \n        <div class=\"pth-faq-card\">\n            <p class=\"pth-faq-q\">Which Boolean operators does the converter support?<\/p>\n            <p class=\"pth-faq-a\">The parser handles AND, OR, NOT, XOR, XNOR, NAND, NOR, and IMPLIES. Variables can be any single letter from A to F. Constants 0 and 1 are also valid inputs. Parentheses control evaluation order exactly as in standard Boolean algebra.<\/p>\n        <\/div>\n \n        <div class=\"pth-faq-card\">\n            <p class=\"pth-faq-q\">How many variables can the truth table handle?<\/p>\n            <p class=\"pth-faq-a\">The truth table supports up to 6 variables, generating a maximum of 64 rows (2\u2076). Expressions with 7 or more unique variables are parsed and converted normally \u2014 the truth table and K-Map tabs simply display a notice that they are limited to 6 variables for performance reasons.<\/p>\n        <\/div>\n \n        <div class=\"pth-faq-card\">\n            <p class=\"pth-faq-q\">What K-Map sizes does the tool render?<\/p>\n            <p class=\"pth-faq-a\">The \ud83d\uddc2\ufe0f K-Map tab renders 2-variable (2\u00d72), 3-variable (2\u00d74), and 4-variable (4\u00d74) maps using correct Gray code ordering. Each cell is color-coded green for output 1 and red for output 0. Expressions with 5 or 6 variables show a notice instead, as 5- and 6-variable maps require 3D representations.<\/p>\n        <\/div>\n \n        <div class=\"pth-faq-card\">\n            <p class=\"pth-faq-q\">Does the VHDL output work directly in Vivado or Quartus?<\/p>\n            <p class=\"pth-faq-a\">Yes. The VHDL code uses IEEE.STD_LOGIC_1164 and follows standard entity\/architecture syntax compatible with Vivado, Quartus Prime, ModelSim, and GHDL. Each of the four VHDL variants \u2014 original, simplified, NAND-only, and NOR-only \u2014 is a complete, self-contained module you can paste directly into your project.<\/p>\n        <\/div>\n \n        <div class=\"pth-faq-card\">\n            <p class=\"pth-faq-q\">How does the NAND\/NOR gate count comparison work?<\/p>\n            <p class=\"pth-faq-a\">The \ud83d\udd22 Gate Count tab counts NAND or NOR keyword occurrences in the optimized converted expression and measures parenthesis nesting depth as a proxy for logic depth. A bar chart scales both implementations against each other, and a verdict line identifies which uses fewer gates for your specific expression.<\/p>\n        <\/div>\n \n        <div class=\"pth-faq-card\">\n            <p class=\"pth-faq-q\">Can I simulate the generated Verilog circuit?<\/p>\n            <p class=\"pth-faq-a\">Yes. Click the <strong>\u25b6 Simulate<\/strong> button in the NAND or NOR tab and the tool opens DigitalJS \u2014 a free browser-based Verilog simulator \u2014 with the code pre-loaded via URL encoding. You can toggle input signals and watch gate-level propagation in real time without installing any software.<\/p>\n        <\/div>\n \n        <div class=\"pth-faq-card\">\n            <p class=\"pth-faq-q\">Does the tool save my conversion history?<\/p>\n            <p class=\"pth-faq-a\">The sidebar history panel saves your last 8 conversions to localStorage in your browser. Click any entry to instantly reload that expression and re-run the full analysis. History persists across page refreshes. Use the <strong>\ud83d\uddd1\ufe0f Clear History<\/strong> button to remove all saved entries at any time.<\/p>\n        <\/div>\n \n        <div class=\"pth-faq-card\">\n            <p class=\"pth-faq-q\">Is any data sent to a server when I convert?<\/p>\n            <p class=\"pth-faq-a\">Nothing is transmitted. The parser, simplifier, Verilog generator, VHDL generator, truth table builder, and K-Map renderer all run entirely in your browser&#8217;s JavaScript engine. Your Boolean expressions and generated circuit designs never leave your device.<\/p>\n        <\/div>\n \n        <div class=\"pth-faq-card\">\n            <p class=\"pth-faq-q\">What is the difference between the NAND tab and the Raw Data tab?<\/p>\n            <p class=\"pth-faq-a\">The <strong>\ud83d\udfe3 NAND<\/strong> tab shows the <em>optimized<\/em> conversion \u2014 the tool first simplifies your expression using Boolean laws, then converts the reduced form to NAND gates. The <strong>\ud83d\udcc2 Raw Data<\/strong> tab shows the <em>unsimplified<\/em> NAND and NOR conversions applied directly to your original expression without any pre-simplification, which is useful for comparing optimization impact.<\/p>\n        <\/div>\n \n    <\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Universal Logic Gate Converter Pro | Boolean to NAND\/NOR 100% offline Advanced Universal Gate Converter. Simplify Boolean expressions step-by-step, convert to raw and optimized NAND\/NOR gates, and generate synthesizable Verilog code instantly. \ud83d\udfe2 8-Tab Results Dashboard Every conversion opens across eight dedicated tabs: Simplify, NAND, NOR, VHDL, Truth Table, K-Map, Gate Count, and Raw Data. &#8230; <a title=\"Universal Logic Gate Converter Pro | Boolean to NAND\/NOR\" class=\"read-more\" href=\"https:\/\/schoolict.net\/tools\/universal-logic-gate-converter-pro\/\" aria-label=\"Read more about Universal Logic Gate Converter Pro | Boolean to NAND\/NOR\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":517,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-230","page","type-page","status-publish","has-post-thumbnail"],"_links":{"self":[{"href":"https:\/\/schoolict.net\/tools\/wp-json\/wp\/v2\/pages\/230","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/schoolict.net\/tools\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/schoolict.net\/tools\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/schoolict.net\/tools\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/schoolict.net\/tools\/wp-json\/wp\/v2\/comments?post=230"}],"version-history":[{"count":0,"href":"https:\/\/schoolict.net\/tools\/wp-json\/wp\/v2\/pages\/230\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/schoolict.net\/tools\/wp-json\/wp\/v2\/media\/517"}],"wp:attachment":[{"href":"https:\/\/schoolict.net\/tools\/wp-json\/wp\/v2\/media?parent=230"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}