Chapter 1.3: Computers
Multiple Choice · Data Representation
Question 1: From Uppercase to Lowercase
In the lecture’s program, a lowercase letter was obtained by adding 32 (00100000) to the code of an uppercase letter (“A” 65 → “a” 97). The code of “G” is 71. Which code does the program produce, and what appears on the screen?
B: 71 + 32 = 103 = “g”. At the bit level, 01000111 + 00100000 = 01100111: uppercase and lowercase letters differ only in the bit of the 32s place. The encoding (ASCII) is what tells us that this bit pattern is a letter.
Step-by-Step Trace · Number Base Conversion
Question 2: 214 in Octal and Hexadecimal
The number 11010110₂ (= 214) is converted to octal and hexadecimal by grouping bits. What are the groups and digits at each step?
Since 8 = 2³, bits are grouped in threes; since 16 = 2⁴, in fours.
Grouping starts from the right; the incomplete group on the far left is padded with 0: 11 → 011.
011 = 3, 010 = 2, 110 = 6 → 326₈.
The octal place values are 64, 8, 1. 214 ✓
Now groups of 4: 1101 and 0110.
1101 = 13 = D, 0110 = 6 → D6₁₆.
Check ✓. Octal and hexadecimal are ways to write long binary numbers briefly.
binary ← 11010110 ; 214 ; octal: group in threes from the right groups ← 011 | 010 | 110 octal ← ? check ← ? ; hexadecimal: group in fours from the right groups ← 1101 | 0110 hex ← ? check ← ?
Output Question · Number Base Conversion
Question 3: From Hexadecimal to Binary
Each hexadecimal digit is 4 bits. Convert the numbers below to binary and decimal:
a) A7₁₆ b) 2C₁₆ c) 3F₁₆
Show answer
a) 10100111₂ = 167 b) 00101100₂ = 44 c) 00111111₂ = 63
- Decimal value: a) 10 · 16 + 7 = 167 · b) 2 · 16 + 12 = 44 · c) 3 · 16 + 15 = 63.
- The letters A–F stand for the values 10–15.
Step-by-Step Trace · Negative Numbers
Question 4: Two’s Complement: −13
How is −13 written in 8-bit two’s complement? Trace the algorithm and check the result by adding +13.
Two steps are enough: flip the bits, then add 1.
+13 = 8 + 4 + 1 → 00001101.
All bits are flipped (0 ↔ 1). This is called the one’s complement.
11110010 + 1 = 11110011. The leftmost 1 shows that the number is negative.
The sum has 9 bits; the 9th bit (carry) does not fit in an 8-bit register and is discarded.
The remainder 00000000 = 0 ✓: 13 + (−13) = 0. The adder circuit does nothing special for negatives.
n ← 13
positive ← binary8(n)
inverted ← flipAllBits(positive)
negative ← inverted + 1
check ← positive + negative
print(negative, last 8 bits of check)Multiple Choice · Overflow
Question 5: A byte Overflow
In which option is the output of the code fragment below given correctly?
byte x = 127;
x++;
x++;
System.out.print(x);A: In Java, byte is an 8-bit two’s-complement number (−128 … 127). 127 + 1 = 01111111 + 1 = 10000000 = −128 (overflow); one more increment gives −127. −128 is only the value after the first increment; 129 does not fit in 8 bits.
Multiple Choice · Overflow
Question 6: 180 + 100 in Unsigned 8 Bits
The operation 180 + 100 is performed in an 8-bit unsigned register. What value remains in the register?
D: 280 does not fit in 8 bits (the maximum is 255). 280 = 100011000₂; the 9th bit (256) is dropped, leaving 00011000 = 24. In short, 280 − 256 = 24 (overflow). The register does not “get stuck” at 255.
Output Question · Floating-Point Numbers
Question 7: 0.1 + 0.2
What is the output of the code below?
System.out.println(0.1 + 0.2);
System.out.println(0.1 + 0.2 == 0.3);
System.out.println(
Math.abs(0.1 + 0.2 - 0.3) < 1e-9);Show answer
Output:
0.30000000000000004 false true
- 0.1 and 0.2 cannot be written exactly with a finite number of bits in binary; rounded versions are stored in a double.
- The sum is very close to 0.3 but not equal to it →
==is false. - Decimal results are compared with a small tolerance → true.
Step-by-Step Trace · Floating-Point Numbers
Question 8: Why Can’t 0.3 Be Stored Exactly?
A decimal fraction is converted to binary by repeatedly multiplying by 2 and taking the integer part. Trace the algorithm for 0.3. Does the expansion end?
In each round the fraction is multiplied by 2; the integer part (0 or 1) is the next bit.
0.3 × 2 = 0.6 → integer part 0.
0.6 × 2 = 1.2 → bit 1, subtract 1 from the fraction: 0.2.
0.2 × 2 = 0.4 → bit 0.
0.4 × 2 = 0.8 → bit 0.
0.8 × 2 = 1.6 → bit 1, fraction 0.6.
0.6 was already seen in the first round: the expansion entered a cycle and never ends. Cutting it off at a finite number of bits causes a small rounding error.
fraction ← 0.3 bits ← “0.” repeat: fraction ← fraction × 2 bit ← integerPart(fraction) bits ← bits + bit fraction ← fraction − bit stop if the fraction was seen before
Multiple Choice · Floating-Point Numbers
Question 9: The Bits of a float
Which are the bit fields of a 32-bit float in the IEEE 754 standard?
C: float = 1 + 8 + 23 = 32 bits. A gives the fields of the 64-bit double (1 + 11 + 52). Value = (−1)^sign × 1.fraction × 2^(exponent − 127); for normal numbers the leading 1 is not stored.
Output Question · Text Representation
Question 10: Calculating with Character Codes
In ASCII the code of the character “0” is 48, and the digits are consecutive. In Java, a char is a numeric code. What is the output of the code below?
char c = '7'; System.out.println(c + 1); System.out.println((char) (c + 1)); System.out.println(c - '0');
Show answer
Output:
56 8 7
- “7” = 48 + 7 = 55.
c + 1is an integer addition → 56. - Converting 56 back to a character gives “8”.
c - '0'= 55 − 48 = 7: the numeric value of the digit character. The type determines the meaning of the same bit pattern.
Step-by-Step Trace · Text Representation
Question 11: Encoding the Word “Ali”
The ASCII codes are A = 65, l = 108, i = 105. What does the algorithm print for each character of the word “Ali”? How many bytes does the word take in memory?
Each character is first converted to a number, and the number to an 8-bit byte.
First character A → 65.
65 = 64 + 1 → 01000001.
Second character l → 108.
108 = 64 + 32 + 8 + 4 → 01101100.
Third character i → 105.
105 = 64 + 32 + 8 + 1 → 01101001.
No characters left. The word takes 3 bytes = 24 bits.
text ← “Ali” for each character c: code ← ASCII(c) print(binary8(code))
Step-by-Step Trace · Text Representation
Question 12: UTF-8 Encoding: “ş”
Unicode assigns the code point U+015F to the letter “ş”. Which bytes does UTF-8 use to store it? The 2-byte template is 110xxxxx 10xxxxxx.
015F₁₆ = 1·256 + 5·16 + 15 = 351.
351 = 256 + 64 + 16 + 8 + 4 + 2 + 1. It does not fit in 7 bits (not ASCII) but fits in 11 bits → 2 bytes.
The 11 bits are split 5 + 6 to fit the x’s in the template.
The leading 110 means “first byte of a 2-byte character”.
The leading 10 means “continuation byte”.
“ş” = C5 9F (2 bytes). ASCII letters take 1, € takes 3, an emoji takes 4 bytes.
c ← “ş”
code ← U+015F
binary ← 11-bit(code)
upper ← first 5 bits
lower ← last 6 bits
byte1 ← 110 + upper
byte2 ← 10 + lower
print(hex(byte1, byte2))Multiple Choice · Text Representation
Question 13: Unicode and UTF-8
Which statement about Unicode and UTF-8 is true?
D: UTF-8 is a variable-length encoding; ASCII characters are written with a single byte, so old ASCII text is valid UTF-8. “A” = U+0041 = 65, the same as ASCII. Unicode covers different writing systems, math symbols and emoji.
Output Question · Logic Gates
Question 14: NOT, AND, OR Together
Find the value of the expression X = NOT (A AND B) OR C for the three cases below (parentheses first, then NOT, finally OR).
a) A = 1, B = 1, C = 0
b) A = 1, B = 0, C = 0
c) A = 1, B = 1, C = 1
Show answer
| A AND B | NOT(…) | OR C | X | |
|---|---|---|---|---|
| a | 1 | 0 | 0 OR 0 | 0 |
| b | 0 | 1 | 1 OR 0 | 1 |
| c | 1 | 0 | 0 OR 1 | 1 |
NOT reverses the value (0 → 1, 1 → 0). A single 1 is enough for OR; so when C = 1, X = 1 whatever A and B are.
Step-by-Step Trace · Logic Gates
Question 15: Binary Addition: 11 + 7
Trace the algorithm that adds 1011₂ + 0111₂ column by column. In each column, what are t, the digit written and the carry?
Right to left, as in decimal. Rule: 1 + 1 = 10₂ (write 0, carry 1).
Column 1: 1 + 1 = 10₂ → write 0, carry 1.
Column 2: 1 + 1 + 1 (carry) = 11₂ → write 1, carry 1.
Column 3: 0 + 1 + 1 = 10₂ → write 0, carry 1.
Column 4: 1 + 0 + 1 = 10₂ → write 0, carry 1.
The last carry is written at the front: 10010₂ = 16 + 2 = 18 = 11 + 7 ✓. The result needed 5 bits.
A ← 1011 ; 11 B ← 0111 ; 7 carry ← 0 for each column i from right to left: t ← A[i] + B[i] + carry digit ← t mod 2 carry ← t div 2 if carry = 1 then write 1 at the front
Step-by-Step Trace · Logic Gates
Question 16: Full Adder: 1 + 0 + 1
A full adder consists of two half adders and an OR gate. For A = 1, B = 0 and incoming carry Cin = 1, what is the output of each gate?
Half adder: SUM = XOR, CARRY = AND. A full adder also adds the incoming carry.
1 XOR 0 = 1 (the inputs differ).
1 AND 0 = 0: no carry from the first addition.
1 XOR 1 = 0: the result digit is 0.
1 AND 1 = 1: the carry came from the second half adder.
0 OR 1 = 1.
(Cout, SUM) = 10₂ = 2 = 1 + 0 + 1 ✓.
A ← 1, B ← 0, Cin ← 1 s1 ← A XOR B ; 1st half adder c1 ← A AND B SUM ← s1 XOR Cin ; 2nd half adder c2 ← s1 AND Cin Cout ← c1 OR c2 print(Cout, SUM)
Step-by-Step Trace · Fetch–Decode–Execute
Question 17: Running a Program Step by Step
The CPU runs the memory contents below starting at address 1000. At each fetch and execute step, what are PC, IR, ACC and memory[1007]?
Start: PC holds the address of the first instruction.
Fetch: the instruction at 1000 goes to IR, and PC increases by one.
Decode + execute: memory[1005] = 9 is read and loaded into ACC.
Fetch: ADD 1006; PC → 1002.
ALU: 9 + 6 = 15.
Fetch: the same instruction once more; PC → 1003.
ALU: 15 + 6 = 21.
Fetch: STORE 1007; PC → 1004.
The 21 in ACC is written to address 1007 over the bus.
Fetch: HALT → the CPU stops. 5 instructions, 5 rounds; the result is 9 + 6 + 6 = 21. Without HALT, the CPU would treat the 9 at 1005 as an instruction.
1000: LOAD 1005 ; ACC ← memory[1005] 1001: ADD 1006 ; ACC ← ACC + memory[1006] 1002: ADD 1006 1003: STORE 1007 ; memory[1007] ← ACC 1004: HALT 1005: 9 1006: 6 1007: 0
Output Question · Fetch–Decode–Execute
Question 18: If the Instructions Swap Places
In the lecture’s program, STORE and ADD have swapped places. When the program finishes, what are ACC and memory[1006]? How many instructions are fetched?
1000: LOAD 1004 1001: STORE 1006 1002: ADD 1005 1003: HALT 1004: 12 1005: 8 1006: 0
Show answer
ACC = 20, memory[1006] = 12; 4 instructions are fetched.
- LOAD → ACC = 12. STORE → memory[1006] = 12 (the ACC at that moment).
- ADD → ACC = 12 + 8 = 20, but this value is never written to memory.
- HALT → stop. The CPU executes instructions in order; the order changes the result.
Multiple Choice · Buses
Question 19: Which Bus Carries the Address?
The CPU is reading the value at address 1004. Which bus carries the number “1004” to memory?
B: The address bus carries which cell is requested and is one-way (it leaves the CPU). The control bus carries READ/WRITE and timing signals, and the two-way data bus carries the contents of the cell.
Output Question · Instruction Encoding
Question 20: Decoding a Machine Instruction
In a hypothetical machine an instruction is 16 bits: the first 4 bits are the opcode (HALT = 0000, LOAD = 0001, ADD = 0010, STORE = 0011), and the remaining 12 bits are the address.
a) Which instruction is 0011 0011 1110 1110?
b) How is LOAD 1004 encoded?
c) How many different addresses can be represented?
Show answer
a) STORE 1006 b) 0001 0011 1110 1100 c) 4,096
- a) 001111101110₂ = 3EE₁₆ = 3·256 + 14·16 + 14 = 1006.
- b) 1004 = 3EC₁₆ = 0011 1110 1100.
- c) 12 bits → 2¹² = 4,096 addresses (0–4095).
Multiple Choice · Computer Architecture
Question 21: The von Neumann Bottleneck
What does the “von Neumann bottleneck” refer to?
A: A shared memory and a shared bus give flexibility (the stored program), but the CPU may sit idle while waiting for data in memory. The cache exists to ease this bottleneck. C is wrong: the stored-program approach, on the contrary, makes updating by software possible.
Multiple Choice · Programming
Question 22: From Java to Assembly
Which is the correct assembly equivalent of the line int diff = a - b;, using the instructions from the lecture?
C: First a is loaded from memory into a register (the ALU works only with registers), then b is subtracted, and finally the result is written to the place of the variable diff. In A the subtraction happens before a is loaded into R1. A single Java line becomes several machine instructions.