← Course Hub← 课程主页 ← All Units← 返回单元列表
H I G H  S C H O O L  C O M P U T E R  S C I E N C E
Solutions详解

Boolean Logic and Number Systems · Solutions布尔逻辑与数制 · 详解

Companion to the Practice Set · Mark-by-mark walkthroughs · AP CSP-Feeder / US / ON / BC / AB styles练习题配套详解 · 逐分讲解 · AP CSP 衔接 / 美 / 安 / 卑 / 阿省考风格

EASY MEDIUM HARD 🇺🇸 US 🇨🇦 ON 🇨🇦 BC 🇨🇦 AB AP CSP-style MCQAP CSP 风格选择题 AP CSP-feeder FRQAP CSP 衔接简答题 ON Provincial-style安大略省考风格 BC Provincial-style卑诗省考风格 AB/Universal Applied阿省/通用应用题 Honors荣誉级


PART I  ·  SHORT RESPONSE  ·  SOLUTIONS第一部分  ·  短答题  ·  详解25 marks共 25 分
Q1 EASY 🇺🇸 US AP CSP-style MCQAP CSP 风格选择题 §1 Binary Number System二进制数制 · AP CSP DAT-1.A [3 marks][3 分]

What is the decimal value of the 8-bit binary number 00110110?8 位二进制数 00110110 的十进制值是多少?

Answer: (B) 54答案:(B) 54

Expand by place value (right to left, starting at 2^0): [1]按权展开(从右到左,从 2^0 开始):[1]

Bit positions with value 1: positions 1 (2^1=2), 2 (2^2=4), 4 (2^4=16), 5 (2^5=32). Sum: 32+16+4+2 = 54. [1]值为 1 的位:位置 1 (2^1=2)、2 (2^2=4)、4 (2^4=16)、5 (2^5=32)。求和:32+16+4+2 = 54。[1]

Distractors: (A) 22 = 00010110 (missing bit5 and bit4). (C) 108 = 01101100. (D) 27 = 00011011. [1]干扰项:(A) 22 = 00010110(缺少第 5、4 位)。(C) 108 = 01101100。(D) 27 = 00011011。[1]

Insight:解题洞察: Identify which bit positions contain a 1, list their powers of 2, and sum them. In 00110110, reading right to left: positions 1 (2), 2 (4), 4 (16), 5 (32) are set. Common errors include reversing the bit order or forgetting that the rightmost bit is 2^0 = 1.找出哪些位为 1,列出对应的 2 的幂次,然后求和。在 00110110 中,从右到左读:第 1 位 (2)、第 2 位 (4)、第 4 位 (16)、第 5 位 (32) 为 1。常见错误是从左到右读(权值反转)或忘记最右位是 2^0 = 1。
Q2 EASY 🇺🇸 US 🇨🇦 ON AP CSP-style MCQAP CSP 风格选择题 §2 Hexadecimal十六进制 · ICS3U A1.2 [3 marks][3 分]

How many bits does a single hexadecimal digit represent, and what is the decimal value of hex digit D?一个十六进制位代表多少位二进制,十六进制数字 D 的十进制值是多少?

Answer: (C) 4 bits; D = 13答案:(C) 4 位;D = 13

Hex is base 16. Since 2^4 = 16, one hex digit encodes exactly 4 bits (one nibble). [1]十六进制以 16 为底。由于 2^4 = 16,一个十六进制位恰好编码 4 位二进制(一个半字节)。[1]

Hex digits A=10, B=11, C=12, D=13, E=14, F=15. So D = 13. [1]十六进制数字:A=10,B=11,C=12,D=13,E=14,F=15。因此 D = 13。[1]

Distractor (A) 8 bits: wrong; 8 bits = 2 hex digits. Distractor (B) D=14: confuses D with E. Distractor (D) 1 bit: confuses nibble with a single binary digit. [1]干扰项 (A) 8 位:错误;8 位 = 2 个十六进制位。干扰项 (B) D=14:将 D 与 E 混淆。干扰项 (D) 1 位:将半字节与单个二进制位混淆。[1]

Insight:解题洞察: Memorise hex letter digits A-F = 10-15. The 4-bit nibble rule is the key to fast binary-hex conversion: every hex digit maps to exactly four binary digits. For example, D = 13 = 1101 in binary.记住十六进制字母位 A-F = 10-15。4 位半字节规则是快速进行二进制-十六进制转换的关键:每个十六进制位恰好对应四个二进制位。例如,D = 13 = 二进制 1101。
Q3 MEDIUM 🇨🇦 ON 🇨🇦 BC ON Provincial-style安大略省考风格 §3 Converting Between Bases进制转换 · ICS3U A1.4 / BC CS10 [5 marks][5 分]

Convert decimal 109 to 8-bit binary using repeated division by 2. Show all steps.用连续除以 2 的方法将十进制数 109 转换为 8 位二进制数,展示所有步骤。

Answer: 01101101答案:01101101

Repeated division by 2 (record remainders, read upward): [3]连续除以 2(记录余数,从下往上读):[3]

Division除法QuotientRemainder (bit)余数(位)
109 / 2541 (LSB)
54 / 2270
27 / 2131
13 / 261
6 / 230
3 / 211
1 / 201 (MSB)

Reading remainders bottom-to-top: 1101101. Pad to 8 bits: 01101101. [1]余数从下往上读:1101101。补足 8 位:01101101[1]

Verify: 64+32+8+4+1 = 109. [1]验证:64+32+8+4+1 = 109。[1]

Insight:解题洞察: The repeated-division method always reads remainders from the last division upward (last remainder = MSB). Verification by expanding back to decimal catches reading-direction mistakes. Odd numbers always end in binary 1 (LSB = 1 when the number is odd).连续除法总是从最后一次除法的余数向上读(最后的余数 = MSB)。用十进制展开验证可以发现读取方向错误。奇数的二进制结果总以 1 结尾(奇数时 LSB = 1)。
Q4 MEDIUM 🇺🇸 US 🇨🇦 ON AP CSP-feeder FRQAP CSP 衔接简答题 §4 Binary Arithmetic二进制算术 · AP CSP DAT-1.B [6 marks][6 分]

Add 4-bit binary numbers 0111 + 0101. Show the carry row and state the 4-bit result and its decimal value.计算 4 位二进制数 0111 + 0101。写出进位行,以及 4 位结果和其十进制值。

Carry row 0111; result 1100; decimal 12进位行 0111;结果 1100;十进制 12

Column-by-column addition (right to left): [3]逐列相加(从右到左):[3]

bit pos位位置3210
carry in进位输入0110
A (0111)0111
B (0101)0101
result结果1100

Bit 0: 1+1+0=2, result 0 carry 1. Bit 1: 1+0+1=2, result 0 carry 1. Bit 2: 1+1+1=3, result 1 carry 1. Bit 3: 0+0+1=1, result 1 carry 0. Result: 1100. [2]第 0 位:1+1+0=2,结果 0 进 1。第 1 位:1+0+1=2,结果 0 进 1。第 2 位:1+1+1=3,结果 1 进 1。第 3 位:0+0+1=1,结果 1 进 0。结果:1100[2]

Decimal check: 7+5=12. Binary 1100 = 8+4 = 12. Carry-out = 0, so no overflow; 12 fits in 4 bits. [1]十进制验证:7+5=12。二进制 1100 = 8+4 = 12。进位输出=0,无溢出,12 可以放入 4 位。[1]

Insight:解题洞察: In binary addition: 1+1 = 10 (binary), result 0 carry 1. Four cases: 0+0=0, 0+1=1, 1+1=10 (carry), 1+1+carry=11 (carry). Always verify by converting result to decimal and comparing with the expected decimal sum.二进制加法中:1+1 = 10(二进制),结果 0 进 1。四种情况:0+0=0,0+1=1,1+1=10(进位),1+1+进位=11(进位)。始终通过将结果转换回十进制与预期十进制和进行验证。
Q5 MEDIUM 🇺🇸 US 🇨🇦 ON 🇨🇦 BC AP CSP-feeder FRQAP CSP 衔接简答题 §5 Representing Text and Data文本与数据表示 · AP CSP DAT-1.A / ICS3U A1.2 [8 marks][8 分]

ASCII encoding questions: 'A'=65, 'a'=97, '0'=48.ASCII 编码问题:'A'=65, 'a'=97, '0'=48

See sub-parts below见以下各小问

(a) ASCII codes: 'C' = 65+2 = 67; 'm' = 97+12 = 109; '3' = 48+3 = 51. [3](a) ASCII 码:'C' = 65+2 = 67;'m' = 97+12 = 109;'3' = 48+3 = 51。[3]

(b) "Hi" has 2 characters; at 1 byte (8 bits) each, it takes 2 bytes = 16 bits to store. [2](b) "Hi" 有 2 个字符,每个字符占 1 字节(8 位),共需 2 字节 = 16 位存储。[2]

(c) 'H' = 72. 72 in binary: 64+8 = 72, so 01001000. [2](c) 'H' = 72。72 的二进制:64+8 = 72,即 01001000[2]

(d) ASCII represents only 128 characters (0-127) and cannot represent characters outside English (accented letters, Chinese characters, emoji, etc.). Unicode (e.g. UTF-8) was developed to support all writing systems worldwide. [1](d) ASCII 只能表示 128 个字符(0-127),无法表示英文以外的字符(带重音字母、汉字、表情符号等)。为支持全球所有文字系统,开发了 Unicode(如 UTF-8)。[1]

Insight:解题洞察: The ASCII table has a mathematical structure: uppercase letters start at 65, lowercase at 97 (difference = 32), digits at 48. This lets you calculate codes mentally. The 32-bit gap between cases also means toggling bit 5 of an ASCII letter switches case.ASCII 表有数学规律:大写字母从 65 开始,小写从 97 开始(差 32),数字从 48 开始,可以心算。大小写之间相差 32,也意味着切换 ASCII 字母的第 5 位可以改变大小写。
PART II  ·  EXTENDED RESPONSE  ·  SOLUTIONS第二部分  ·  延伸回答  ·  详解30 marks共 30 分
Q6 EASY 🇺🇸 US 🇨🇦 ON AP CSP-feeder FRQAP CSP 衔接简答题 §6 Boolean Logic布尔逻辑 · AP CSP AAP-2.H / CSTA 3A-DA-09 [4 marks][4 分]

Complete the truth table for AND, OR, and NOT A with inputs A and B.补全以 A 和 B 为输入的 AND、OR 和 NOT A 真值表。

Answer: see completed table below答案:见以下完整表格
ABA AND BA OR BNOT A
TTTTF
TFFTF
FTFTT
FFFFT

AND is True only when BOTH inputs are True. OR is True when at least one input is True. NOT flips A. [3] for the three columns; [1] for all rows correct in each column.AND 仅当两个输入均为 True 时为 True。OR 当至少一个输入为 True 时为 True。NOT 取反 A。[3] 为三列;[1] 为每列所有行正确。

Insight:解题洞察: A truth table with two inputs always has 2^2 = 4 rows. Memory shortcut: AND = both must be True; OR = either one is enough; NOT = opposite. AND with T,F or F,T both give F, while OR gives T both times.两个输入的真值表总有 2^2 = 4 行。记忆技巧:AND = 两者都必须为 True;OR = 任一为 True 即可;NOT = 取反。AND 在 T,F 或 F,T 时均为 F,而 OR 两种情况均为 T。
Q7 MEDIUM 🇺🇸 US 🇨🇦 BC AP CSP-feeder FRQAP CSP 衔接简答题 §2 + §3 Hex + Base Conversion十六进制 + 进制转换 · AP CSP DAT-1.A / BC CS11 [8 marks][8 分]

HTML color code #B43C00: decode each channel, convert R to binary, convert decimal 200 to hex.HTML 颜色码 #B43C00:解码每个通道,将 R 转为二进制,将十进制 200 转为十六进制。

R=180, G=60, B=0; R binary=10110100; 200 hex=0xC8R=180,G=60,B=0;R 二进制=10110100;200 十六进制=0xC8

(a) Each hex pair is one byte. B4: B=11, so B4 = 11*16+4 = 180. 3C: 3*16+12 = 60. 00 = 0. R=180, G=60, B=0. [3](a) 每对十六进制为一字节。B4:B=11,B4 = 11*16+4 = 180。3C:3*16+12 = 60。00 = 0。R=180,G=60,B=0。[3]

(b) 180 in binary: 128+32+16+4 = 180. Set bits: 7 (128), 5 (32), 4 (16), 2 (4). Result: 10110100. Verify: 128+32+16+4=180. [3](b) 180 转二进制:128+32+16+4 = 180。置 1 的位:7 (128)、5 (32)、4 (16)、2 (4)。结果:10110100。验证:128+32+16+4=180。[3]

(c) 200 in hex: 200/16 = 12 remainder 8. 12/16 = 0 remainder 12 = C. Reading up: 0xC8. [2](c) 200 转十六进制:200/16 = 12 余 8。12/16 = 0 余 12 = C。从下往上读:0xC8。[2]

Insight:解题洞察: Hex is the web developer's shorthand for RGB: each of the three color channels (0-255) maps to exactly two hex digits. This is why CSS color codes are always 6 hex digits. The nibble method is faster for binary-to-hex: split 10110100 into 1011 (B=11) and 0100 (4), giving 0xB4 directly.十六进制是网页开发者描述 RGB 的简写:三个颜色通道(0-255)各自对应两个十六进制位,这也是 CSS 颜色码总是 6 位十六进制的原因。半字节法更适合二进制转十六进制:将 10110100 分为 1011(B=11)和 0100(4),直接得到 0xB4。
Q8 MEDIUM 🇺🇸 US 🇨🇦 ON AP CSP-feeder FRQAP CSP 衔接简答题 §4 Binary Arithmetic + Overflow二进制算术 + 溢出 · AP CSP DAT-1.B / ICS3U A1.4 [8 marks][8 分]

Problem A: 0011 + 0100. Problem B: 1101 + 0111 (4-bit registers).问题 A:0011 + 0100。问题 B:1101 + 0111(4 位寄存器)。

A: 0111 = 7 (no overflow); B: overflow, stored = 0100 = 4 (true sum = 20)A:0111 = 7(无溢出);B:溢出,存储值 = 0100 = 4(真实和 = 20)

(a) Problem A: 0011 + 0100, no carries. Bit 0: 1+0=1. Bit 1: 1+0=1. Bit 2: 0+1=1. Bit 3: 0+0=0. Result = 0111 = 7. Decimal: 3+4=7. Carry-out=0, no overflow. [2](a) 问题 A: 0011 + 0100,无进位。第 0 位:1+0=1。第 1 位:1+0=1。第 2 位:0+1=1。第 3 位:0+0=0。结果 = 0111 = 7。十进制:3+4=7。进位输出=0,无溢出。[2]

(b) Problem B: 1101 + 0111, decimal 13+7=20. 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. Carry-out = 1, 4-bit stored = 0100 = 4. [2](b) 问题 B: 1101 + 0111,十进制 13+7=20。第 0 位:1+1=0 进 1;第 1 位:0+1+1=0 进 1;第 2 位:1+1+1=1 进 1;第 3 位:1+0+1=0 进 1。进位输出=1,4 位存储值 = 0100 = 4。[2]

A 4-bit register holds at most 15 (1111). 20 requires 5 bits (10100); the 5th bit is lost, leaving 0100 = 4. This is overflow: the stored result is wrong because the register is too small. [2]4 位寄存器最多存储 15(1111)。20 需要 5 位(10100),第 5 位丢失,只剩 0100 = 4。这就是溢出:因为寄存器太小,存储结果出错。[2]

Overflow is signalled by a carry-out from the most significant bit. It occurs when the true mathematical result exceeds the representable range (0-15 for 4-bit unsigned). [2]溢出由最高有效位的进位输出标识。当真实数学结果超过可表示范围(4 位无符号数为 0-15)时发生溢出。[2]

Insight:解题洞察: The stored result after overflow equals the true sum modulo 2^n: 20 mod 16 = 4. This explains why overflow bugs produce small nonsense values instead of the expected large result, a dangerous class of software error that has caused real-world security vulnerabilities.溢出后的存储结果等于真实和对 2^n 取模:20 mod 16 = 4。这解释了为什么溢出错误会产生小的无意义值而非预期的大值,这是一类危险的软件错误,曾导致现实中的安全漏洞。
Q9 HARD 🇺🇸 US 🇨🇦 ON AP CSP-feeder FRQAP CSP 衔接简答题 Honors荣誉级 §6 + §7 Compound Boolean + De Morgan's复合布尔 + 德摩根定律 · AP CSP AAP-2.H / ICS3U A1.4 [10 marks][10 分]

Expression: (NOT A) AND (B OR C). Complete the truth table, identify true rows, apply De Morgan's, write Python.表达式:(NOT A) AND (B OR C)。补全真值表,找出 True 的行,应用德摩根定律,写 Python。

3 rows True (A=0 with B or C=1); De Morgan: A OR (NOT B AND NOT C); Python: (not A) and (B or C)3 行为 True(A=0 且 B 或 C 为 1);德摩根:A OR (NOT B AND NOT C);Python:(not A) and (B or C)

(a) Truth table (8 rows, 3 inputs): [4](a) 真值表(8 行,3 个输入):[4]

ABCNOT AB OR COut
000100
001111
010111
011111
100000
101010
110010
111010

(b) 3 rows output 1: (A=0,B=0,C=1), (A=0,B=1,C=0), (A=0,B=1,C=1). All share A=0 and at least one of B or C = 1. [2](b) 3 行输出为 1:(A=0,B=0,C=1)、(A=0,B=1,C=0)、(A=0,B=1,C=1)。共同特征:A=0 且 B 或 C 至少一个为 1。[2]

(c) De Morgan's law: NOT(X AND Y) = (NOT X) OR (NOT Y). Apply to complement: NOT[(NOT A) AND (B OR C)] = NOT(NOT A) OR NOT(B OR C) = A OR (NOT B AND NOT C). [2](c) 德摩根定律:NOT(X AND Y) = (NOT X) OR (NOT Y)。对整个表达式取反:NOT[(NOT A) AND (B OR C)] = NOT(NOT A) OR NOT(B OR C) = A OR (NOT B AND NOT C)。[2]

(d) Python: (not A) and (B or C). [1](d) Python:(not A) and (B or C)[1]

(e) Honors: NOT(B OR C) = (NOT B) AND (NOT C) by De Morgan's. Double negation NOT NOT A = A. So the complement simplifies to A OR (NOT B AND NOT C). This expression is False exactly when A=0 and at least one of B, C is 1 (the same rows where the original is True). [1](e) 荣誉级: 由德摩根定律 NOT(B OR C) = (NOT B) AND (NOT C)。双重否定 NOT NOT A = A。因此补集化简为 A OR (NOT B AND NOT C)。此表达式恰好在 A=0 且 B、C 至少有一个为 1 时为 False(即原表达式为 True 的行)。[1]

Insight:解题洞察: De Morgan's two laws: NOT(A AND B) = (NOT A) OR (NOT B) and NOT(A OR B) = (NOT A) AND (NOT B). They let you distribute NOT inside compound expressions, essential for circuit simplification and logical negation in code. The AND/OR always flips when NOT moves through it.德摩根两条定律:NOT(A AND B) = (NOT A) OR (NOT B);NOT(A OR B) = (NOT A) AND (NOT B)。它们允许将 NOT 分配到复合表达式内部,是电路化简和代码逻辑取反的关键。NOT 移入时 AND/OR 总是互换。
PART III  ·  MODELING & APPLIED  ·  SOLUTIONS第三部分  ·  建模与应用  ·  详解25 marks共 25 分
Q10 MEDIUM 🇺🇸 US 🇨🇦 ON AP CSP-feeder FRQAP CSP 衔接简答题 §7 Logic Gates and Truth Tables逻辑门与真值表 · CSTA 3B-CS-02 [8 marks][8 分]

Circuit: Out = (A AND B) OR (NOT A). Complete truth table, count True rows, simplify for A=1, NAND gate.电路:Out = (A AND B) OR (NOT A)。补全真值表,计算 True 行数,当 A=1 时化简,NAND 门。

3 of 4 rows True; when A=1, Out = B; NAND(1,0) = 14 行中 3 行为 True;当 A=1 时,Out = B;NAND(1,0) = 1

(a) Completed truth table: [4](a) 完整真值表:[4]

ABA AND BNOT AOut输出
00011
01011
10000
11101

(b) 3 rows have Out = 1: (0,0), (0,1), (1,1). [2](b) 3 行 Out = 1:(0,0)、(0,1)、(1,1)。[2]

(c) When A = 1: NOT A = 0. Out = (1 AND B) OR 0 = B OR 0 = B. The circuit passes B through unchanged. [1](c) 当 A = 1 时:NOT A = 0。Out = (1 AND B) OR 0 = B OR 0 = B。电路直接将 B 输出(不变)。[1]

(d) NAND(A=1, B=0): AND(1,0) = 0; NAND = NOT(0) = 1. Output = 1. [1](d) NAND(A=1, B=0):AND(1,0) = 0;NAND = NOT(0) = 1。输出 = 1。[1]

Insight:解题洞察: The expression (A AND B) OR (NOT A) is equivalent to NOT A OR B. It is True whenever A = 0 (NOT A dominates) or when both A and B = 1. The only False case is A=1, B=0. This is also equivalent to the logical implication A IMPLIES B: True except when A is True and B is False.表达式 (A AND B) OR (NOT A) 等价于 NOT A OR B。当 A=0 时(NOT A 起主导)或 A=B=1 时均为 True。唯一 False 的情况是 A=1,B=0。这也等价于逻辑蕴含 A IMPLIES B:仅当 A 为 True 且 B 为 False 时为 False。
Q11 MEDIUM 🇨🇦 BC 🇨🇦 AB BC Provincial-style卑诗省考风格 §5 + §6 ASCII + Boolean in codeASCII + 代码中的布尔逻辑 · AB CSE1120 / BC CS11 [9 marks][9 分]

Checking uppercase ASCII letters (A-Z = 65-90) and digits (0-9 = 48-57) using Boolean logic in Python.使用 Python 中的布尔逻辑检查大写 ASCII 字母(A-Z = 65-90)和数字(0-9 = 48-57)。

See sub-parts below见以下各小问

(a) Evaluate is_upper for each character: [3](a) 对每个字符求 is_upper[3]

'M' (77): 77 >= 65 True AND 77 <= 90 True. is_upper = True.'M'(77):77 >= 65 为 True 且 77 <= 90 为 True。is_upper = True

'z' (122): 122 >= 65 True AND 122 <= 90 False. is_upper = False.'z'(122):122 >= 65 为 True 且 122 <= 90 为 False。is_upper = False

'3' (51): 51 >= 65 False (short-circuit). is_upper = False.'3'(51):51 >= 65 为 False(短路求值)。is_upper = False

(b) is_upper_or_digit = (code >= 65 and code <= 90) or (code >= 48 and code <= 57). [3](b) is_upper_or_digit = (code >= 65 and code <= 90) or (code >= 48 and code <= 57)[3]

(c) De Morgan's: NOT(uppercase OR digit) = (NOT uppercase) AND (NOT digit). In Python: (code < 65 or code > 90) and (code < 48 or code > 57). [3](c) 德摩根定律:NOT(大写 OR 数字) = (NOT 大写) AND (NOT 数字)。Python:(code < 65 or code > 90) and (code < 48 or code > 57)[3]

Insight:解题洞察: Python's and operator short-circuits: if the first operand is False, the second is never evaluated. De Morgan's NOT(A OR B) becomes (NOT A) AND (NOT B), flipping OR to AND and negating each part. For ranges, NOT(code >= 65 and code <= 90) becomes (code < 65 or code > 90).Python 的 and 运算符短路求值:若第一个操作数为 False,第二个永不求值。德摩根定律将 NOT(A OR B) 转为 (NOT A) AND (NOT B),OR 翻转为 AND 并对每部分取反。对于范围:NOT(code >= 65 and code <= 90) 变为 (code < 65 or code > 90)。
Q12 HARD 🇺🇸 US 🇨🇦 ON 🇨🇦 BC AP CSP-feeder FRQAP CSP 衔接简答题 §1 + §3 + §4 + §7 Bits, Conversion, Arithmetic, Gates位、转换、算术、逻辑门 · AP CSP DAT-1 / CSTA 3A-DA-09 [8 marks][8 分]

4-bit ALU: A = 0b1001 (9), B = 0b0110 (6). Bitwise AND, bitwise OR (convert to hex), binary addition with overflow analysis, register capacity.4 位 ALU:A = 0b1001(9),B = 0b0110(6)。按位 AND、按位 OR(转十六进制)、二进制加法及溢出分析、寄存器容量。

AND = 0000 = 0; OR = 1111 = 15 = 0xF; A+B = 15, 4-bit 1111, no overflow; 16 values, 0-15AND = 0000 = 0;OR = 1111 = 15 = 0xF;A+B = 15,4 位 1111,无溢出;16 个值,0-15

(a) Bitwise AND: A=1001, B=0110. Each bit: 1 AND 0=0; 0 AND 1=0; 0 AND 1=0; 1 AND 0=0. Result: 0000 = 0. [2](a) 按位 AND: A=1001,B=0110。逐位:1 AND 0=0;0 AND 1=0;0 AND 1=0;1 AND 0=0。结果:0000 = 0。[2]

(b) Bitwise OR: A=1001, B=0110. Each bit: 1 OR 0=1; 0 OR 1=1; 0 OR 1=1; 1 OR 0=1. Result: 1111 = 15. In hex: 15 = F, so 0xF. [2](b) 按位 OR: A=1001,B=0110。逐位:1 OR 0=1;0 OR 1=1;0 OR 1=1;1 OR 0=1。结果:1111 = 15。十六进制:15 = F,即 0xF[2]

(c) Binary addition: 9+6=15. 1001+0110: bit0: 1+0=1; bit1: 0+1=1; bit2: 0+1=1; bit3: 1+0=1; carry-out=0. Result: 01111 (5-bit) = 1111 (4-bit) = 15. Carry-out=0 means no overflow; 15 fits exactly in 4 bits. [3](c) 二进制加法: 9+6=15。1001+0110:第 0 位:1+0=1;第 1 位:0+1=1;第 2 位:0+1=1;第 3 位:1+0=1;进位输出=0。结果:01111(5 位)= 1111(4 位)= 15。进位输出=0,无溢出,15 恰好可以放入 4 位。[3]

(d) A 4-bit register holds 2^4 = 16 distinct values. Minimum unsigned = 0 (0000). Maximum unsigned = 15 (1111). [1](d) 4 位寄存器可存储 2^4 = 16 个不同值。无符号最小值 = 0(0000)。无符号最大值 = 15(1111)。[1]

Insight:解题洞察: When A and B have no overlapping 1-bits (as 1001 and 0110 do here), their bitwise AND is all zeros and their bitwise OR is all ones. AND = intersection, OR = union. The addition 9+6=15 is the largest possible 4-bit result without overflow, making these inputs a good boundary test case.当 A 和 B 没有重叠的 1 位时(如此处的 1001 和 0110),按位 AND 全为零,按位 OR 全为一。AND = 交集,OR = 并集。加法 9+6=15 是 4 位无溢出的最大值,使这对输入成为很好的边界测试用例。