Companion to the Practice Set · Mark-by-mark walkthroughs · AP CSP-Feeder / US / ON / BC / AB styles练习题配套详解 · 逐分讲解 · AP CSP 衔接 / 美 / 安 / 卑 / 阿省考风格
What is the decimal value of the 8-bit binary number 00110110?8 位二进制数 00110110 的十进制值是多少?
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]
How many bits does a single hexadecimal digit represent, and what is the decimal value of hex digit D?一个十六进制位代表多少位二进制,十六进制数字 D 的十进制值是多少?
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]
Convert decimal 109 to 8-bit binary using repeated division by 2. Show all steps.用连续除以 2 的方法将十进制数 109 转换为 8 位二进制数,展示所有步骤。
01101101答案:01101101Repeated division by 2 (record remainders, read upward): [3]连续除以 2(记录余数,从下往上读):[3]
| Division除法 | Quotient商 | Remainder (bit)余数(位) |
|---|---|---|
| 109 / 2 | 54 | 1 (LSB) |
| 54 / 2 | 27 | 0 |
| 27 / 2 | 13 | 1 |
| 13 / 2 | 6 | 1 |
| 6 / 2 | 3 | 0 |
| 3 / 2 | 1 | 1 |
| 1 / 2 | 0 | 1 (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]
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 位结果和其十进制值。
1100; decimal 12进位行 0111;结果 1100;十进制 12Column-by-column addition (right to left): [3]逐列相加(从右到左):[3]
| bit pos位位置 | 3 | 2 | 1 | 0 |
|---|---|---|---|---|
| carry in进位输入 | 0 | 1 | 1 | 0 |
| A (0111) | 0 | 1 | 1 | 1 |
| B (0101) | 0 | 1 | 0 | 1 |
| result结果 | 1 | 1 | 0 | 0 |
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]
ASCII encoding questions: 'A'=65, 'a'=97, '0'=48.ASCII 编码问题:'A'=65, 'a'=97, '0'=48。
(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]
Complete the truth table for AND, OR, and NOT A with inputs A and B.补全以 A 和 B 为输入的 AND、OR 和 NOT A 真值表。
| A | B | A AND B | A OR B | NOT A |
|---|---|---|---|---|
| T | T | T | T | F |
| T | F | F | T | F |
| F | T | F | T | T |
| F | F | F | F | T |
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] 为每列所有行正确。
HTML color code #B43C00: decode each channel, convert R to binary, convert decimal 200 to hex.HTML 颜色码 #B43C00:解码每个通道,将 R 转为二进制,将十进制 200 转为十六进制。
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]
Problem A: 0011 + 0100. Problem B: 1101 + 0111 (4-bit registers).问题 A:0011 + 0100。问题 B:1101 + 0111(4 位寄存器)。
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]
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。
(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]
| A | B | C | NOT A | B OR C | Out |
|---|---|---|---|---|---|
| 0 | 0 | 0 | 1 | 0 | 0 |
| 0 | 0 | 1 | 1 | 1 | 1 |
| 0 | 1 | 0 | 1 | 1 | 1 |
| 0 | 1 | 1 | 1 | 1 | 1 |
| 1 | 0 | 0 | 0 | 0 | 0 |
| 1 | 0 | 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 0 | 1 | 0 |
| 1 | 1 | 1 | 0 | 1 | 0 |
(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]
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 门。
(a) Completed truth table: [4](a) 完整真值表:[4]
| A | B | A AND B | NOT A | Out输出 |
|---|---|---|---|---|
| 0 | 0 | 0 | 1 | 1 |
| 0 | 1 | 0 | 1 | 1 |
| 1 | 0 | 0 | 0 | 0 |
| 1 | 1 | 1 | 0 | 1 |
(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]
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)。
(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]
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)。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(转十六进制)、二进制加法及溢出分析、寄存器容量。
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]