Boolean Logic and Number Systems布尔逻辑与数制
Computers speak in binary: every piece of data — a number, a letter, an image — is ultimately a string of 0s and 1s. This guide builds the full picture from the ground up: how the binary number system works and why base-2 maps perfectly onto hardware; how hexadecimal gives programmers a compact shorthand; how to convert fluently between decimal, binary, and hex; how to add in binary; how text is encoded as ASCII and Unicode; and how Boolean logic — AND, OR, NOT — connects the world of numbers to the logic gates that make up every circuit. Truth tables appear throughout so you can reason about any logical expression by hand.计算机用二进制(binary,二进制)"说话":每一份数据——数字、字母、图像——最终都是一串 0 和 1。本指南从零开始建立完整体系:二进制数制(binary number system)如何工作,以及为何以 2 为底完美地映射到硬件;十六进制(hexadecimal,十六进制)如何给程序员提供紧凑的简写;如何在十进制(decimal,十进制)、二进制和十六进制之间流畅转换;如何做二进制加法;文本如何被编码为 ASCII 和 Unicode;以及布尔逻辑(Boolean logic,布尔逻辑)——与(AND)、或(OR)、非(NOT)——如何将数字世界与构成每个电路的逻辑门(logic gate,逻辑门)连接起来。真值表(truth table,真值表)贯穿全文,使你能够手工推理任意逻辑表达式。
How to use this guide如何使用本指南
Boolean logic and number systems appear in all four curricula, though with varying depth. Ontario ICS3U is the most explicit: A1.2 names binary, hexadecimal, ASCII, and Unicode verbatim; A1.4 names AND, OR, NOT verbatim. US CSTA 3A-DA-09 links bit representation to characters, numbers, images, and explicitly mentions logic gates in its Descriptive Statement. AP CSP Big Idea 2 (Data) covers binary numbers and bit representation (topics 2.1–2.2). BC names Boolean operators in Computer Studies 10 but has no explicit binary/hex conversion standard. Alberta names Boolean operators in CSE1120 and ASCII/binary encoding in CSE2130 but has no dedicated number-systems module. The table below maps each section to your curriculum.布尔逻辑和数制在四套课程中均有出现,但深度各异。安大略 ICS3U 最为明确:A1.2 原文点名二进制、十六进制、ASCII 和 Unicode;A1.4 原文点名 AND、OR、NOT。美国 CSTA 3A-DA-09 将位表示与字符、数字、图像关联,其描述性说明明确提及逻辑门。AP CSP 大概念 2(数据)涵盖二进制数和位表示(主题 2.1–2.2)。BC 在 Computer Studies 10 中命名了布尔运算符,但无明确的二进制/十六进制转换标准。阿尔伯塔在 CSE1120 中命名了布尔运算符、在 CSE2130 中命名了 ASCII/二进制编码,但无专门的数制模块。下表将每节内容映射到你的课程。
| If you are in…如果你在… | Focus on these sections重点学习 | Defer / lighter可推迟 / 减负 | Source依据 |
|---|---|---|---|
| 🇺🇸 US CSTA / AP CSP美国 CSTA / AP CSP | §1–§5 (binary, hex, conversions, ASCII/Unicode, bit/byte) are the core of AP CSP Big Idea 2 (DAT-1.A, DAT-1.B). §6–§7 (Boolean logic, gates) map to CSTA 3A-DA-09 Descriptive Statement and 3B-CS-02.§1–§5(二进制、十六进制、转换、ASCII/Unicode、位/字节)是 AP CSP 大概念 2(DAT-1.A、DAT-1.B)的核心。§6–§7(布尔逻辑、逻辑门)对应 CSTA 3A-DA-09 描述性说明和 3B-CS-02。 | Logic gate circuit diagrams (§7 going-deeper) are enrichment for AP CSP students; the exam tests Boolean expressions, not physical gate drawing.逻辑门电路图(§7 深入)对 AP CSP 学生为拓展内容;考试测试布尔表达式,而非物理门图。 | CSTA K-12 and AP CSP — CSTA 3A-DA-09, 3B-CS-02; AP CSP Big Idea 2 (DAT) topics 2.1, 2.2— CSTA 3A-DA-09、3B-CS-02;AP CSP 大概念 2(DAT)主题 2.1、2.2 |
| 🇨🇦 ON Grade 11 — ICS3U安大略 11 年级 — ICS3U | All seven sections. ICS3U A1.2 explicitly names binary, hex, ASCII, Unicode (§1–§5). ICS3U A1.4 explicitly names AND, OR, NOT (§6–§7). The most direct curriculum match of all four regions.全部 7 节。ICS3U A1.2 明确点名二进制、十六进制、ASCII、Unicode(§1–§5)。ICS3U A1.4 明确点名 AND、OR、NOT(§6–§7)。四个地区中课程匹配度最高。 | Nothing — the whole unit is assessed in ICS3U Strand A.无——整个单元均在 ICS3U A 单元中评估。 | ON/BC Computer Studies 11-12 — ICS3U A1.2, A1.4— ICS3U A1.2、A1.4 |
| 🇨🇦 BC — CS10 / CIS11BC — CS10 / CIS11 | §6 (Boolean logic: AND, OR, NOT) is the strongest curriculum match (CS10 intro-constructs Content). §5 (ASCII/Unicode, bit/byte) connects to CIS11 data-encoding Content. §1–§4 (binary/hex/conversion) are conceptual enrichment — BC has no explicit base-conversion standard.§6(布尔逻辑:AND、OR、NOT)是课程匹配度最高的(CS10 入门构造内容)。§5(ASCII/Unicode、位/字节)与 CIS11 数据编码内容关联。§1–§4(二进制/十六进制/转换)为概念拓展——BC 无明确的进制转换标准。 | §7 logic gates going-deeper is enrichment for BC; BC names Boolean operators as a programming construct, not as circuit-level hardware.§7 逻辑门深入对 BC 为拓展;BC 将布尔运算符命名为编程构造,而非电路级硬件。 | ON/BC Computer Studies 11-12 — BC CS10 Boolean operators content bullet; CIS11 data encoding content— BC CS10 布尔运算符内容条目;CIS11 数据编码内容 |
| 🇨🇦 AB — CSE1120 / CSE2130阿尔伯塔 — CSE1120 / CSE2130 | §6 (Boolean operators in programs, CSE1120 outcome 2.6) and §5 (ASCII/binary encoding, CSE2130 outcome 1.1.2) are the assessed content. §1–§4 (binary/hex/arithmetic) are enrichment — Alberta CSE has no dedicated number-base module.§6(程序中的布尔运算符,CSE1120 结果 2.6)和 §5(ASCII/二进制编码,CSE2130 结果 1.1.2)是被评估的内容。§1–§4(二进制/十六进制/算术)为拓展——阿尔伯塔 CSE 无专门的进制模块。 | §7 (logic gates) is enrichment for AB; digital logic / number systems are in other CTS clusters, not CSE.§7(逻辑门)对 AB 为拓展;数字逻辑/数制在其他 CTS 集群中,不在 CSE 中。 | Alberta CTS Computing Science — CSE1120 outcomes 2.3, 2.6; CSE2130 outcome 1.1.2— CSE1120 结果 2.3、2.6;CSE2130 结果 1.1.2 |
Memorise five things: how to count in binary and convert a small number to/from decimal; what a bit and byte are; the three Boolean operators AND, OR, NOT and their truth tables; what ASCII is; and how to evaluate a simple Boolean expression. Read every cram-cheat box. Skip the logic gate circuit diagrams in §7 going-deeper.背熟五件事:如何用二进制计数并将小数字与十进制互转;位和字节是什么;AND、OR、NOT 三个布尔运算符及其真值表;ASCII 是什么;以及如何求一个简单布尔表达式的值。读每个速记框,跳过 §7 深入中的逻辑门电路图。
Master fluent conversion in all three directions (binary ↔ decimal ↔ hex). Be able to construct a full truth table for a compound expression like (A AND B) OR (NOT C). Understand why each binary digit doubles the representable range. Know the Unicode extension story beyond ASCII. AP CSP DAT-1.A and DAT-1.B, and Ontario ICS3U A1.2 + A1.4, are the exam anchors for full marks.掌握三个方向的流畅转换(二进制 ↔ 十进制 ↔ 十六进制)。能够为复合表达式(如 (A AND B) OR (NOT C))构建完整真值表。理解为何每个二进制位将可表示范围翻倍。了解 ASCII 之外的 Unicode 扩展故事。AP CSP DAT-1.A 和 DAT-1.B 以及安大略 ICS3U A1.2 + A1.4 是满分的考试锚点。
The Binary Number System二进制数制
- Bit位(bit) — a single binary digit: 0 or 1.— 单个二进制位:0 或 1。
- Byte字节(byte) — 8 bits. 1 byte can represent 28 = 256 distinct values (0–255).— 8 位。1 字节可表示 28 = 256 个不同值(0–255)。
- Place values double left-to-right位权从右往左翻倍 — in decimal, columns are 1, 10, 100, 1000. In binary they are 1, 2, 4, 8, 16, 32, 64, 128.— 十进制中各列位权为 1、10、100、1000;二进制中为 1、2、4、8、16、32、64、128。
Read the 8-bit number 10110101 and find its decimal value.读取 8 位二进制数 10110101,求其十进制值。
| Bit position位位置 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
|---|---|---|---|---|---|---|---|---|
| Place value (2n)位权(2n) | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
| Bit位 | 1 | 0 | 1 | 1 | 0 | 1 | 0 | 1 |
| Contribution贡献值 | 128 | 0 | 32 | 16 | 0 | 4 | 0 | 1 |
Sum: 128 + 32 + 16 + 4 + 1 = 181.求和:128 + 32 + 16 + 4 + 1 = 181。
Each 1-bit contributes its place value; 0-bits contribute nothing. Add up only the columns where the bit is 1.每个 1 位贡献其位权;0 位不贡献任何值。只将位为 1 的列的位权相加。
Hexadecimal十六进制
- Digits: 0–9 then A=10, B=11, C=12, D=13, E=14, F=15.数字:0–9,然后 A=10、B=11、C=12、D=13、E=14、F=15。
- One byte (8 bits) = exactly 2 hex digits. e.g. 0xFF = 1111 1111 = decimal 255.一字节(8 位)= 恰好 2 个十六进制位。例如 0xFF = 1111 1111 = 十进制 255。
- Hex prefix:
0xin code (e.g.0x1F);#in HTML color codes (e.g.#FF0000= pure red).十六进制前缀:代码中用0x(如0x1F);HTML 颜色代码中用#(如#FF0000= 纯红色)。
Show the 16 hex digits and their binary/decimal equivalents, then decode the color #3A7FBE.列出 16 个十六进制数字及其对应的二进制/十进制值,然后解码颜色代码 #3A7FBE。
| Hex十六进制 | Decimal十进制 | 4-bit binary4 位二进制 | Hex十六进制 | Decimal十进制 | 4-bit binary4 位二进制 |
|---|---|---|---|---|---|
| 0 | 0 | 0000 | 8 | 8 | 1000 |
| 1 | 1 | 0001 | 9 | 9 | 1001 |
| 2 | 2 | 0010 | A | 10 | 1010 |
| 3 | 3 | 0011 | B | 11 | 1011 |
| 4 | 4 | 0100 | C | 12 | 1100 |
| 5 | 5 | 0101 | D | 13 | 1101 |
| 6 | 6 | 0110 | E | 14 | 1110 |
| 7 | 7 | 0111 | F | 15 | 1111 |
Decoding #3A7FBE (RGB color):解码 #3A7FBE(RGB 颜色):
#3A7FBE → R=0x3A G=0x7F B=0xBE
R: 3=0011, A=1010 → 0011 1010 = 58 (decimal)
G: 7=0111, F=1111 → 0111 1111 = 127 (decimal)
B: B=1011, E=1110 → 1011 1110 = 190 (decimal)
Each pair of hex digits is one byte (0–255). The color #3A7FBE has red=58, green=127, blue=190 — a medium steel-blue.每对十六进制位代表一字节(0–255)。颜色 #3A7FBE 的红色=58、绿色=127、蓝色=190——一种中等钢蓝色。
Converting Between Bases进制转换
- Binary → Decimal二进制 → 十进制 — multiply each bit by its place value (1, 2, 4, 8, …) and sum.— 每位乘以其位权(1、2、4、8……)后求和。
- Decimal → Binary十进制 → 二进制 — divide by 2 repeatedly; remainders (read bottom-up) are the binary digits.— 反复除以 2;余数(从下往上读)即为二进制位。
- Binary ↔ Hex二进制 ↔ 十六进制 — group bits in fours from the right; look up each group in the hex table.— 从右侧起每 4 位分为一组;在十六进制表中查找每组的值。
Convert decimal 45 to (a) binary and (b) hexadecimal.将十进制 45 转换为 (a) 二进制和 (b) 十六进制。
(a) Decimal 45 → Binary (repeated division by 2).(a) 十进制 45 → 二进制(反复除以 2)。
45 ÷ 2 = 22 remainder 1 ← least significant bit (LSB)
22 ÷ 2 = 11 remainder 0
11 ÷ 2 = 5 remainder 1
5 ÷ 2 = 2 remainder 1
2 ÷ 2 = 1 remainder 0
1 ÷ 2 = 0 remainder 1 ← most significant bit (MSB)
Read remainders bottom-up: 101101
Pad to 8 bits: 00101101
Check: 32 + 8 + 4 + 1 = 45. Correct.验证:32 + 8 + 4 + 1 = 45。正确。
(b) Binary 00101101 → Hex (group into nibbles).(b) 二进制 00101101 → 十六进制(分成半字节)。
0010 | 1101
2 | D
Result: 0x2D
Left nibble 0010 = 2; right nibble 1101 = 13 = D. So 45 decimal = 0x2D hex.左半字节 0010 = 2;右半字节 1101 = 13 = D。因此十进制 45 = 十六进制 0x2D。
Binary Arithmetic (Addition)二进制算术(加法)
- 0 + 0 = 0 (no carry)(无进位)
- 0 + 1 = 1 (no carry)(无进位)
- 1 + 0 = 1 (no carry)(无进位)
- 1 + 1 = 10 (write 0, carry 1 — exactly like decimal 9+1=10 but happens at 2 not 10)(写 0,进位 1——就像十进制中 9+1=10,但在 2 而不是 10 时发生)
Calculate (a) 0110 + 0101 and (b) 1101 + 0111 in binary. Check against decimal.计算二进制 (a) 0110 + 0101 和 (b) 1101 + 0111。与十进制结果对照验证。
(a) 0110 + 0101 (= decimal 6 + 5 = 11).(a) 0110 + 0101(= 十进制 6 + 5 = 11)。
0 1 1 0
+ 0 1 0 1
---------
carry: 0 1 1 0
Step by step (right to left):
bit 0: 0+1 = 1, carry 0
bit 1: 1+0 = 1, carry 0
bit 2: 1+1 = 0, carry 1
bit 3: 0+0+1(carry) = 1, carry 0
Result: 1011 (= 8+2+1 = 11 decimal) ✓
(b) 1101 + 0111 (= decimal 13 + 7 = 20).(b) 1101 + 0111(= 十进制 13 + 7 = 20)。
1 1 0 1
+ 0 1 1 1
---------
bit 0: 1+1 = 0, carry 1
bit 1: 0+1+1 = 0, carry 1
bit 2: 1+1+1 = 1, carry 1
bit 3: 1+0+1 = 0, carry 1
Result: 1 0100 (5 bits needed)
Binary: 10100 = 16+4 = 20 decimal ✓
If restricted to 4-bit storage, the carry-out bit is lost and the result would be 0100 = 4 — an overflow error.如果限制为 4 位存储,进位位丢失,结果将是 0100 = 4——这是一个溢出错误。
Representing Text and Data (ASCII, Unicode, Bits and Bytes)文本与数据表示(ASCII、Unicode、位与字节)
- ASCIIASCII — 7 bits, 128 characters (0–127). Covers A–Z, a–z, 0–9, punctuation, and control codes. 'A' = 65, 'a' = 97, '0' = 48.— 7 位,128 个字符(0–127)。涵盖 A–Z、a–z、0–9、标点和控制字符。'A' = 65,'a' = 97,'0' = 48。
- UnicodeUnicode — superset of ASCII; over 140,000 characters covering virtually every writing system (Chinese, Arabic, emoji, …). Common encoding: UTF-8 (variable 1–4 bytes; first 128 code points are identical to ASCII).— ASCII 的超集;超过 140,000 个字符,涵盖几乎所有书写系统(中文、阿拉伯文、表情符号……)。常见编码:UTF-8(可变 1–4 字节;前 128 个码点与 ASCII 完全相同)。
- Bit and byte scale位与字节的换算 — 1 byte = 8 bits; 1 KB = 1,024 bytes; 1 MB = 1,024 KB; 1 GB = 1,024 MB.— 1 字节 = 8 位;1 KB = 1,024 字节;1 MB = 1,024 KB;1 GB = 1,024 MB。
Show how the two-character string "Hi" is stored in memory using ASCII, in both decimal and binary.展示双字符字符串"Hi"如何用 ASCII 在内存中存储,包括十进制和二进制形式。
| Character字符 | ASCII decimalASCII 十进制 | Binary (8-bit)二进制(8 位) | Hex十六进制 |
|---|---|---|---|
| 'H' | 72 | 01001000 | 0x48 |
| 'i' | 105 | 01101001 | 0x69 |
Storage: 2 characters × 1 byte = 2 bytes = 16 bits total.存储:2 个字符 × 1 字节 = 2 字节 = 共 16 位。
Note: 'H' (uppercase) = 72, 'h' (lowercase) = 104. The difference is 32, which means lowercase = uppercase + 32 in ASCII — a useful pattern for case-conversion code.注意:'H'(大写)= 72,'h'(小写)= 104。差值为 32,即 ASCII 中小写 = 大写 + 32——这是大小写转换代码的有用规律。
Why Unicode extends ASCII.为什么 Unicode 扩展了 ASCII。 ASCII's 128 code points cannot represent Chinese characters, Arabic script, or emoji. Unicode assigns a unique code point to every character in every writing system. UTF-8 encodes the first 128 Unicode code points identically to ASCII (backward-compatible), then uses 2–4 bytes for the rest. The Chinese character 中 is Unicode code point U+4E2D, encoded in UTF-8 as three bytes: 0xE4 0xB8 0xAD.ASCII 的 128 个码点无法表示汉字、阿拉伯文字或表情符号。Unicode 为每种书写系统中的每个字符分配唯一码点。UTF-8 将前 128 个 Unicode 码点与 ASCII 完全相同地编码(向后兼容),其余使用 2–4 字节。汉字"中"是 Unicode 码点 U+4E2D,在 UTF-8 中编码为三字节:0xE4 0xB8 0xAD。
Boolean Logic: AND, OR, NOT布尔逻辑:与、或、非
- ANDAND(与) — result is TRUE only when both inputs are TRUE. In code:
A and B.— 只有当两个输入都为 TRUE 时结果才为 TRUE。代码中:A and B。 - OROR(或) — result is TRUE when at least one input is TRUE. In code:
A or B.— 当至少一个输入为 TRUE 时结果为 TRUE。代码中:A or B。 - NOTNOT(非) — flips the input: NOT TRUE = FALSE, NOT FALSE = TRUE. In code:
not A.— 取反:NOT TRUE = FALSE,NOT FALSE = TRUE。代码中:not A。
Build the truth tables for all three operators and evaluate the expression (A AND B) OR (NOT C) for A=T, B=F, C=F.为三个运算符建立真值表,并求 A=T、B=F、C=F 时表达式 (A AND B) OR (NOT C) 的值。
AND truth tableAND(与)真值表
| A | B | A AND B |
|---|---|---|
| T | T | T |
| T | F | F |
| F | T | F |
| F | F | F |
OR truth tableOR(或)真值表
| A | B | A OR B |
|---|---|---|
| T | T | T |
| T | F | T |
| F | T | T |
| F | F | F |
NOT: NOT T = F; NOT F = T.NOT(非):NOT T = F;NOT F = T。
Evaluating (A AND B) OR (NOT C) with A=T, B=F, C=F:求 A=T、B=F、C=F 时 (A AND B) OR (NOT C) 的值:
Step 1: A AND B = T AND F = F
Step 2: NOT C = NOT F = T
Step 3: F OR T = T
Result: TRUE
Evaluate inside parentheses first, then combine with the outer operator — same operator-precedence rule as arithmetic.先求括号内的值,再与外层运算符结合——与算术中的运算符优先级规则相同。
Going deeper — Boolean expressions in programming conditions深入 — 编程条件中的布尔表达式
In code, Boolean expressions appear inside if statements and while loops. Compound conditions combine comparison operators with Boolean operators: e.g. if (age >= 16 and has_license). De Morgan's Laws are useful for simplification: NOT (A AND B) = (NOT A) OR (NOT B); NOT (A OR B) = (NOT A) AND (NOT B). These let you rewrite negated compound conditions into a form that is easier to read and test.在代码中,布尔表达式出现在 if 语句和 while 循环中。复合条件将比较运算符与布尔运算符结合:例如 if (age >= 16 and has_license)。德摩根定律对化简很有用:NOT (A AND B) = (NOT A) OR (NOT B);NOT (A OR B) = (NOT A) AND (NOT B)。这些定律使你能够将取反的复合条件改写为更易读、更易测试的形式。
Logic Gates and Truth Tables逻辑门与真值表
- AND gateAND 门(与门) — two inputs; output is 1 only when both inputs are 1.— 两个输入;只有当两个输入都为 1 时输出为 1。
- OR gateOR 门(或门) — two inputs; output is 1 when at least one input is 1.— 两个输入;至少一个输入为 1 时输出为 1。
- NOT gate / inverterNOT 门 / 反相器(非门) — one input; output is the complement (0→1, 1→0).— 一个输入;输出为补(0→1,1→0)。
Build the truth table for the circuit: Output = (A AND B) OR (NOT A). Use 0/1 notation.为以下电路建立真值表:输出 = (A AND B) OR (NOT A)。使用 0/1 表示法。
| A | B | A AND B | NOT A | Output: (A AND B) OR (NOT A)输出:(A AND B) OR (NOT A) |
|---|---|---|---|---|
| 0 | 0 | 0 | 1 | 1 |
| 0 | 1 | 0 | 1 | 1 |
| 1 | 0 | 0 | 0 | 0 |
| 1 | 1 | 1 | 0 | 1 |
Reading the table: whenever A=0, NOT A=1, so the OR is always 1. When A=1, NOT A=0, so the output equals A AND B = B. The circuit behaves like a conditional: "give me B, but only when A is 1; otherwise output 1."读表:只要 A=0,NOT A=1,则 OR 结果始终为 1。当 A=1 时,NOT A=0,输出等于 A AND B = B。该电路的行为类似于条件:当 A=1 时输出 B,否则输出 1。
How to build any truth table:如何构建任意真值表:
1. List all input combinations (n inputs = 2^n rows).
2 inputs → 4 rows: 00, 01, 10, 11
3 inputs → 8 rows: 000, 001, 010, 011, 100, 101, 110, 111
2. Add intermediate columns for each sub-expression.
3. Fill the final output column by evaluating each row.
Going deeper — NAND, NOR, and universal gates深入 — NAND、NOR 与通用门
NAND (NOT AND) and NOR (NOT OR) are each universal gates: any Boolean function can be built from NAND gates alone (or NOR gates alone). This is why real CPUs are built almost entirely from NAND gates — they are cheaper to fabricate in CMOS. NAND truth table: output is 0 only when both inputs are 1 (the complement of AND). XOR (exclusive OR) outputs 1 when exactly one input is 1 (not both) — used in binary addition circuits (the sum bit of a half adder is XOR, the carry bit is AND).NAND(NOT AND)和 NOR(NOT OR)各自都是通用门:任何布尔函数都可以仅用 NAND 门(或仅用 NOR 门)构建。这就是为什么真实 CPU 几乎完全由 NAND 门构成——它们在 CMOS 工艺中制造成本更低。NAND 真值表:只有当两个输入都为 1 时输出才为 0(AND 的补)。XOR(异或)在恰好一个输入为 1(而非两个都是)时输出 1——用于二进制加法电路(半加器的和位是 XOR,进位位是 AND)。
Exam Strategy and Common Pitfalls考试策略与常见陷阱
- Always show the place-value table.始终列出位权表。 For binary-to-decimal, write out the column headers (128, 64, 32, 16, 8, 4, 2, 1) and fill in the bits. Examiners award method marks even when the final answer is wrong.对于二进制转十进制,写出列标题(128、64、32、16、8、4、2、1)并填入位值。即使最终答案错误,考官也会给方法分。
- Hex ↔ binary: go via nibbles.十六进制 ↔ 二进制:通过半字节转换。 Never convert hex to decimal then to binary. Split hex digits into 4-bit nibbles directly. 0xB3 = 1011 0011, not "179 in decimal first."不要将十六进制先转十进制再转二进制。直接将十六进制位拆成 4 位半字节。0xB3 = 1011 0011,而不是"先转为十进制 179"。
- Binary addition: track carries explicitly.二进制加法:明确追踪进位。 Write the carry row above the addition. Forgetting to propagate a carry is the most common arithmetic error. Check by converting both operands to decimal, adding, then converting back.在加法上方写出进位行。忘记传播进位是最常见的算术错误。通过将两个操作数转换为十进制相加后再转回来验证。
- Know the key ASCII anchors.记住关键 ASCII 锚点。 'A'=65, 'a'=97, '0'=48. From these, any letter or digit offset is computable: 'C' = 65+2 = 67; 'z' = 97+25 = 122.'A'=65,'a'=97,'0'=48。从这些锚点出发,任何字母或数字的偏移量都可以计算:'C' = 65+2 = 67;'z' = 97+25 = 122。
- Unicode ≠ ASCII for non-Latin characters.非拉丁字符中 Unicode ≠ ASCII。 ASCII cannot encode Chinese, Arabic, or emoji. State this explicitly when a question involves non-English text.ASCII 无法编码中文、阿拉伯文或表情符号。当题目涉及非英文文本时,请明确说明这一点。
- Build the truth table column by column.逐列构建真值表。 For a compound expression, add one intermediate column per operator. Never try to evaluate the whole expression in your head per row — evaluate sub-expressions first.对于复合表达式,每个运算符增加一个中间列。不要试图在脑子里逐行求整个表达式——先求子表达式。
- AND vs OR: the decisive test.AND 与 OR 的决定性测试。 AND is FALSE unless all inputs are TRUE. OR is TRUE unless all inputs are FALSE. Test with all-FALSE and all-TRUE inputs first — those two rows distinguish AND from OR immediately.除非所有输入都为 TRUE,否则 AND 为 FALSE。除非所有输入都为 FALSE,否则 OR 为 TRUE。首先用全 FALSE 和全 TRUE 输入测试——这两行能立即区分 AND 和 OR。
- n inputs = 2n rows.n 个输入 = 2n 行。 Always check that your truth table has the right number of rows before filling it in.在填写真值表之前,始终检查行数是否正确。
- Use 0 and 1, not T and F, for gate questions.逻辑门题中用 0 和 1,而非 T 和 F。 Hardware and circuit questions conventionally use 0/1. Logical expressions in code use TRUE/FALSE. Use the notation the question uses.硬件和电路题习惯用 0/1。代码中的逻辑表达式用 TRUE/FALSE。使用题目所用的表示法。
- Verify conversions in both directions.双向验证转换。 After converting decimal 45 to binary 00101101, always verify: 32+8+4+1=45. This 10-second check prevents losing marks on arithmetic slips.将十进制 45 转换为二进制 00101101 后,始终验证:32+8+4+1=45。这个 10 秒检查可防止因算术失误丢分。
Flashcards闪卡
Practice Quiz综合测验
Readiness Checklist准备就绪清单
Tick each item when you can do it cold, without notes, on a first attempt.能在无笔记、首次尝试下完成,再勾选每一项。
- Convert any 8-bit binary number to decimal using a place-value table (columns 128, 64, 32, 16, 8, 4, 2, 1). Verify by summing the place values where the bit is 1. 🇺🇸 CSTA 3A-DA-09 / 🇨🇦 ON ICS3U A1.2用位权表(各列:128、64、32、16、8、4、2、1)将任意 8 位二进制数转换为十进制。通过将位为 1 的各列位权相加来验证。🇺🇸 CSTA 3A-DA-09 / 🇨🇦 ON ICS3U A1.2
- Convert a decimal number (0–255) to 8-bit binary using repeated division by 2. 🇨🇦 ON ICS3U A1.2用反复除以 2 的方法将十进制数(0–255)转换为 8 位二进制。🇨🇦 ON ICS3U A1.2
- Convert an 8-bit binary number to hexadecimal by grouping into two nibbles. Recite the 16 hex digits (0–9, A–F) and their 4-bit binary equivalents. 🇺🇸 CSTA 3A-DA-09 / 🇨🇦 ON ICS3U A1.2通过分成两个半字节将 8 位二进制数转换为十六进制。背出 16 个十六进制数字(0–9、A–F)及其对应的 4 位二进制值。🇺🇸 CSTA 3A-DA-09 / 🇨🇦 ON ICS3U A1.2
- Add two 4-bit binary numbers showing the carry row, and identify what overflow means when the result exceeds 4 bits. 🇺🇸 AP CSP DAT-1.B写出进位行,将两个 4 位二进制数相加,并说明结果超出 4 位时溢出意味着什么。🇺🇸 AP CSP DAT-1.B
- State the ASCII decimal codes for 'A' (65), 'a' (97), and '0' (48), and explain why lowercase = uppercase + 32. 🇨🇦 ON ICS3U A1.2 / AB CSE2130说出 'A'(65)、'a'(97)和 '0'(48)的 ASCII 十进制码,并解释为什么小写 = 大写 + 32。🇨🇦 ON ICS3U A1.2 / AB CSE2130
- Explain the relationship between ASCII and Unicode: Unicode is a superset, the first 128 code points are identical, and UTF-8 uses 1–4 bytes per character. 🇨🇦 ON ICS3U A1.2解释 ASCII 与 Unicode 的关系:Unicode 是超集,前 128 个码点完全相同,UTF-8 每字符使用 1–4 字节。🇨🇦 ON ICS3U A1.2
- Write the truth tables for AND, OR, and NOT from memory. Evaluate a compound Boolean expression such as (A AND B) OR (NOT C) for given values of A, B, C. 🇨🇦 ON ICS3U A1.4 / AB CSE1120 / BC CS10凭记忆写出 AND、OR 和 NOT 的真值表。为 A、B、C 的给定值求复合布尔表达式(如 (A AND B) OR (NOT C))的值。🇨🇦 ON ICS3U A1.4 / AB CSE1120 / BC CS10
- Build a full truth table for a 2-input logic expression, listing all 4 input combinations in systematic order (00, 01, 10, 11) with one intermediate column per sub-expression. 🇺🇸 CSTA 3B-CS-02为 2 输入逻辑表达式构建完整真值表,以系统顺序(00、01、10、11)列出全部 4 种输入组合,每个子表达式一个中间列。🇺🇸 CSTA 3B-CS-02
- State the CSTA standard 3A-DA-09 (verbatim or near-verbatim) and name the three real-world conversion examples in its Descriptive Statement (hex color codes, ASCII/Unicode, logic gates). 🇺🇸 CSTA Level 3A逐字(或近逐字)陈述 CSTA 标准 3A-DA-09,并说出其描述性说明中的三个现实世界转换示例(十六进制颜色代码、ASCII/Unicode、逻辑门)。🇺🇸 CSTA Level 3A
- Explain why n bits can represent 2n distinct values, and calculate: how many values fit in 1 byte (8 bits), in 16 bits, and in 32 bits. 🇺🇸 AP CSP DAT-1.A解释为什么 n 位可以表示 2n 个不同值,并计算:1 字节(8 位)、16 位和 32 位各能容纳多少个值。🇺🇸 AP CSP DAT-1.A
- Honors — 3B-CS-02 Describe what an AND gate, OR gate, and NOT gate do at the hardware level, and explain why NAND is a universal gate (any Boolean function can be built from NAND gates alone). 🇺🇸 CSTA 3B-CS-02荣誉 — 3B-CS-02 描述 AND 门、OR 门和 NOT 门在硬件层面的功能,并解释为什么 NAND 是通用门(任何布尔函数都可以仅用 NAND 门构建)。🇺🇸 CSTA 3B-CS-02
What This Feeds Into本单元的去向
Binary representation, Boolean logic, and data encoding underpin nearly every other topic in computer science. Control flow uses Boolean expressions in every if-statement and while-loop. Data structures store values using bit-level representations. Networks transmit binary data encoded in bytes. Understanding this unit makes every subsequent unit more legible because you will know what the hardware is actually doing beneath the abstraction layers.二进制表示、布尔逻辑和数据编码几乎支撑着计算机科学中的每个其他主题。控制流在每个 if 语句和 while 循环中使用布尔表达式。数据结构使用位级表示在内存中存储值。网络以字节编码的二进制数据进行传输。理解本单元会使每个后续单元更加清晰,因为你将了解硬件在抽象层之下实际在做什么。
Within High School Computer Science.在 HS Computer Science 内部。
Programming Fundamentals (Unit 2) uses Boolean data types and operators directly in code — the truth tables here give you the exact semantics. Control Flow (Unit 3) builds compound conditions from Boolean operators. Strings and Text Processing (Unit 6) depends on character encoding (ASCII / Unicode) established here. Networks and the Internet (Unit 11) transmits binary data in packets — bytes, bits, and hex addresses are the vocabulary of that unit.编程基础(单元 2)在代码中直接使用布尔数据类型和运算符——这里的真值表给出了确切的语义。控制流(单元 3)从布尔运算符构建复合条件。字符串与文本处理(单元 6)依赖于此处建立的字符编码(ASCII / Unicode)。网络与互联网(单元 11)以数据包传输二进制数据——字节、位和十六进制地址是该单元的词汇。
AP feeder.AP 衔接。
AP CSP Big Idea 2 (Data, 17–22% of the exam) is the direct downstream assessment of §1–§5. Learning Objectives DAT-1.A and DAT-1.B are the exam anchors. AP CSA (Java) uses boolean as a primitive type with operators &&, ||, ! — the same AND/OR/NOT under Java syntax. Fluency with truth tables from this guide transfers directly to AP CSA boolean expression questions.AP CSP 大概念 2(数据,占考试 17–22%)是 §1–§5 的直接下游评估。学习目标 DAT-1.A 和 DAT-1.B 是考试锚点。AP CSA(Java)将 boolean 用作原始类型,运算符为 &&、||、!——即 Java 语法下的 AND/OR/NOT。本指南的真值表熟练度直接迁移到 AP CSA 布尔表达式题目。