2026-02-18 15:52:55 +08:00
|
|
|
|
<template>
|
|
|
|
|
|
<div class="logic-gate-demo">
|
|
|
|
|
|
<div class="demo-header">
|
|
|
|
|
|
<span class="title">逻辑门:用开关做运算</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
2026-02-22 18:26:19 +08:00
|
|
|
|
<p class="intro">
|
|
|
|
|
|
输入 A、B 只能是 0 或 1;四种门按不同规则输出一个 0 或 1。下面表格列出所有 4 种输入组合的结果。
|
|
|
|
|
|
</p>
|
2026-02-18 15:52:55 +08:00
|
|
|
|
|
2026-02-21 10:04:47 +08:00
|
|
|
|
<div class="truth-section">
|
|
|
|
|
|
<table>
|
|
|
|
|
|
<thead>
|
|
|
|
|
|
<tr>
|
|
|
|
|
|
<th>A</th>
|
|
|
|
|
|
<th>B</th>
|
|
|
|
|
|
<th>AND</th>
|
|
|
|
|
|
<th>OR</th>
|
|
|
|
|
|
<th>NOT(A)</th>
|
|
|
|
|
|
<th>XOR</th>
|
|
|
|
|
|
</tr>
|
|
|
|
|
|
</thead>
|
|
|
|
|
|
<tbody>
|
2026-02-22 18:26:19 +08:00
|
|
|
|
<tr v-for="row in truthRows" :key="`${row.a}-${row.b}`">
|
2026-02-21 10:04:47 +08:00
|
|
|
|
<td>{{ row.a }}</td>
|
|
|
|
|
|
<td>{{ row.b }}</td>
|
2026-02-22 18:26:19 +08:00
|
|
|
|
<td>{{ row.and }}</td>
|
|
|
|
|
|
<td>{{ row.or }}</td>
|
|
|
|
|
|
<td>{{ row.not }}</td>
|
|
|
|
|
|
<td>{{ row.xor }}</td>
|
2026-02-21 10:04:47 +08:00
|
|
|
|
</tr>
|
|
|
|
|
|
</tbody>
|
|
|
|
|
|
</table>
|
2026-02-22 18:26:19 +08:00
|
|
|
|
<ul class="col-meaning">
|
|
|
|
|
|
<li><strong>AND</strong>:两个都是 1 才输出 1(像串联:都通才通)</li>
|
|
|
|
|
|
<li><strong>OR</strong>:有一个 1 就输出 1(像并联:一通就通)</li>
|
|
|
|
|
|
<li><strong>NOT(A)</strong>:对 A 取反,0→1、1→0</li>
|
|
|
|
|
|
<li><strong>XOR</strong>:两个不同输出 1,相同输出 0</li>
|
|
|
|
|
|
</ul>
|
2026-02-21 10:04:47 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
|
2026-02-18 15:52:55 +08:00
|
|
|
|
<div class="info-box">
|
2026-02-22 18:26:19 +08:00
|
|
|
|
<strong>核心思想:</strong>逻辑门用晶体管的“开关”组合实现这四种运算,复杂计算都由它们组合而成。
|
2026-02-18 15:52:55 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script setup>
|
2026-02-21 10:04:47 +08:00
|
|
|
|
const truthRows = [
|
2026-02-22 18:26:19 +08:00
|
|
|
|
{ a: 0, b: 0, and: 0, or: 0, not: 1, xor: 0 },
|
|
|
|
|
|
{ a: 0, b: 1, and: 0, or: 1, not: 1, xor: 1 },
|
|
|
|
|
|
{ a: 1, b: 0, and: 0, or: 1, not: 0, xor: 1 },
|
|
|
|
|
|
{ a: 1, b: 1, and: 1, or: 1, not: 0, xor: 0 }
|
2026-02-21 10:04:47 +08:00
|
|
|
|
]
|
2026-02-18 15:52:55 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
|
.logic-gate-demo {
|
|
|
|
|
|
border: 1px solid var(--vp-c-divider);
|
|
|
|
|
|
border-radius: 8px;
|
|
|
|
|
|
background: var(--vp-c-bg-soft);
|
|
|
|
|
|
padding: 1rem;
|
|
|
|
|
|
margin: 1rem 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.demo-header {
|
2026-02-22 18:26:19 +08:00
|
|
|
|
margin-bottom: 0.5rem;
|
2026-02-18 15:52:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-21 10:04:47 +08:00
|
|
|
|
.demo-header .title {
|
|
|
|
|
|
font-weight: bold;
|
|
|
|
|
|
font-size: 1rem;
|
2026-02-18 15:52:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-22 18:26:19 +08:00
|
|
|
|
.intro {
|
|
|
|
|
|
font-size: 0.9rem;
|
2026-02-21 10:04:47 +08:00
|
|
|
|
color: var(--vp-c-text-2);
|
2026-02-22 18:26:19 +08:00
|
|
|
|
margin: 0 0 0.75rem;
|
|
|
|
|
|
line-height: 1.5;
|
2026-02-18 15:52:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-21 10:04:47 +08:00
|
|
|
|
.truth-section {
|
|
|
|
|
|
margin-bottom: 0;
|
2026-02-18 15:52:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
table {
|
|
|
|
|
|
width: 100%;
|
|
|
|
|
|
border-collapse: collapse;
|
2026-02-21 10:04:47 +08:00
|
|
|
|
table-layout: fixed;
|
2026-02-22 18:26:19 +08:00
|
|
|
|
font-size: 0.88rem;
|
|
|
|
|
|
margin-bottom: 0.75rem;
|
2026-02-18 15:52:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-21 10:04:47 +08:00
|
|
|
|
th,
|
|
|
|
|
|
td {
|
2026-02-18 15:52:55 +08:00
|
|
|
|
border: 1px solid var(--vp-c-divider);
|
2026-02-22 18:26:19 +08:00
|
|
|
|
padding: 0.4rem 0.5rem;
|
2026-02-21 10:04:47 +08:00
|
|
|
|
vertical-align: middle;
|
2026-02-18 15:52:55 +08:00
|
|
|
|
text-align: center;
|
2026-02-21 10:04:47 +08:00
|
|
|
|
font-variant-numeric: tabular-nums;
|
2026-02-18 15:52:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
th {
|
|
|
|
|
|
background: var(--vp-c-bg-alt);
|
2026-02-21 10:04:47 +08:00
|
|
|
|
font-weight: 600;
|
2026-02-18 15:52:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-22 18:26:19 +08:00
|
|
|
|
.col-meaning {
|
|
|
|
|
|
margin: 0;
|
|
|
|
|
|
padding-left: 1.25rem;
|
|
|
|
|
|
font-size: 0.85rem;
|
|
|
|
|
|
color: var(--vp-c-text-2);
|
|
|
|
|
|
line-height: 1.6;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.col-meaning li {
|
|
|
|
|
|
margin-bottom: 0.25rem;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.col-meaning strong {
|
|
|
|
|
|
color: var(--vp-c-text-1);
|
|
|
|
|
|
font-variant-numeric: tabular-nums;
|
2026-02-18 15:52:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.info-box {
|
2026-02-22 18:26:19 +08:00
|
|
|
|
display: flex;
|
|
|
|
|
|
gap: 0.25rem;
|
2026-02-18 15:52:55 +08:00
|
|
|
|
background: var(--vp-c-bg-alt);
|
|
|
|
|
|
padding: 0.75rem;
|
|
|
|
|
|
border-radius: 6px;
|
|
|
|
|
|
font-size: 0.85rem;
|
|
|
|
|
|
color: var(--vp-c-text-2);
|
|
|
|
|
|
margin-top: 0.75rem;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-21 10:04:47 +08:00
|
|
|
|
.info-box strong {
|
|
|
|
|
|
white-space: nowrap;
|
|
|
|
|
|
flex-shrink: 0;
|
|
|
|
|
|
}
|
2026-02-18 15:52:55 +08:00
|
|
|
|
</style>
|