diff --git a/docs/.vitepress/config.mjs b/docs/.vitepress/config.mjs index ac3f1da..92a42ca 100644 --- a/docs/.vitepress/config.mjs +++ b/docs/.vitepress/config.mjs @@ -589,7 +589,6 @@ export default defineConfig({ items: [ { text: '集成开发环境 (IDE) 基础', link: '/zh-cn/appendix/2-development-tools/ide-basics' }, { text: '命令行与 Shell 脚本', link: '/zh-cn/appendix/2-development-tools/command-line-shell' }, - { text: '编辑器与 AI 编程助手', link: '/zh-cn/appendix/2-development-tools/editors-and-ai' }, { text: 'Git:代码的时光机', link: '/zh-cn/appendix/2-development-tools/git-version-control' }, { text: '环境变量与 PATH', link: '/zh-cn/appendix/2-development-tools/environment-path' }, { text: '端口与 localhost', link: '/zh-cn/appendix/2-development-tools/ports-localhost' }, diff --git a/docs/.vitepress/theme/components/appendix/computer-fundamentals/AdderDemo.vue b/docs/.vitepress/theme/components/appendix/computer-fundamentals/AdderDemo.vue index 389acad..9ff3077 100644 --- a/docs/.vitepress/theme/components/appendix/computer-fundamentals/AdderDemo.vue +++ b/docs/.vitepress/theme/components/appendix/computer-fundamentals/AdderDemo.vue @@ -1,87 +1,128 @@ @@ -100,47 +141,46 @@ const toggleBit = (arr, i) => { } } -const decimalA = computed(() => { - return bitsA.value.reduce((acc, bit, i) => acc + bit * Math.pow(2, 3-i), 0) -}) +const decimalA = computed(() => + bitsA.value.reduce((acc, bit, i) => acc + bit * Math.pow(2, 3 - i), 0) +) -const decimalB = computed(() => { - return bitsB.value.reduce((acc, bit, i) => acc + bit * Math.pow(2, 3-i), 0) -}) +const decimalB = computed(() => + bitsB.value.reduce((acc, bit, i) => acc + bit * Math.pow(2, 3 - i), 0) +) -const carries = computed(() => { - const c = [0, 0, 0, 0] +const stageData = computed(() => { + const stages = [] + let carry = 0 + const posNames = ['最低位', '次低位', '次高位', '最高位'] for (let i = 3; i >= 0; i--) { - const sum = bitsA.value[i] + bitsB.value[i] + (i < 3 ? c[i+1] : 0) - c[i] = sum >= 2 ? 1 : 0 + const a = bitsA.value[i] + const b = bitsB.value[i] + const total = a + b + carry + const sum = total % 2 + const carryOut = total >= 2 ? 1 : 0 + stages.push({ + bitPos: 3 - i, + posName: posNames[3 - i], + a, + b, + carryIn: stages.length > 0 ? carry : null, + sum, + carryOut + }) + carry = carryOut } - return c + return stages }) -const sumBits = computed(() => { - const s = [0, 0, 0, 0] - for (let i = 3; i >= 0; i--) { - const sum = bitsA.value[i] + bitsB.value[i] + (i < 3 ? carries.value[i+1] : 0) - s[i] = sum % 2 - } - return s -}) +const sumBits = computed(() => stageData.value.map((s) => s.sum).reverse()) const resultBinary = computed(() => { - const allBits = [carries.value[0], ...sumBits.value] - return allBits.join('') + const lastCarry = stageData.value[stageData.value.length - 1]?.carryOut || 0 + return (lastCarry ? lastCarry.toString() : '') + sumBits.value.join('') }) -const resultDecimal = computed(() => { - return decimalA.value + decimalB.value -}) - -const stages = [ - { label: '第4位 (个位)' }, - { label: '第3位' }, - { label: '第2位' }, - { label: '第1位 (最高位)' } -] +const resultDecimal = computed(() => decimalA.value + decimalB.value) diff --git a/docs/.vitepress/theme/components/appendix/computer-fundamentals/AlgorithmDemo.vue b/docs/.vitepress/theme/components/appendix/computer-fundamentals/AlgorithmDemo.vue index 312104a..56bd51e 100644 --- a/docs/.vitepress/theme/components/appendix/computer-fundamentals/AlgorithmDemo.vue +++ b/docs/.vitepress/theme/components/appendix/computer-fundamentals/AlgorithmDemo.vue @@ -1,7 +1,6 @@