ITPEC FE Subject B April 2025 Question 4
ITPEC FE Subject B April 2025 — Question 4 of 20
Binary to Decimal Conversion — fill in blanks for a function that interprets a decimal-digit string of 0s and 1s as a binary number.
The function peels off one digit at a time from the right using n mod 10. Each digit is either 0 or 1 — it is the current bit. To get its decimal contribution, multiply it by the positional weight (place), which starts at 1 and doubles each iteration (powers of two: 1, 2, 4, 8, …).
Trace with number = 1100:
| Step | n | remainder | decimal += remainder × place | place (next) |
|---|---|---|---|---|
| 1 | 1100 | 0 | 0 + 0×1 = 0 | 2×1 = 2 |
| 2 | 110 | 0 | 0 + 0×2 = 0 | 2×2 = 4 |
| 3 | 11 | 1 | 0 + 1×4 = 4 | 2×4 = 8 |
| 4 | 1 | 1 | 4 + 1×8 = 12 | 2×8 = 16 |
Result: decimal = 12 ✓
- •A = `remainder × place` — current bit × positional weight
- •B = `2 × place` — double the weight for the next binary position
Why not others:
- (a) 2 × place for A would ignore the actual bit value; n × place for B makes no sense as a weight update
- (b) 2 × place for A is wrong — you need the bit, not a constant multiplier
- (c) 10 × place for A treats it as decimal positional notation, not binary
- (d) 10 × place for A is decimal, not binary
- (e) n × place for A uses the entire remaining number, not just the current digit
- (f) n × place for A — same issue as (e)
- (h) 10 × place for B would give decimal positional weights (1, 10, 100…), not binary
Key rule: Binary positional weights are powers of 2 — the weight doubles each step (place ← 2 × place), and each bit's contribution is bit × place.
AI-generated — may contain errors
The original exam layout is preserved in the image so diagrams, formulas, tables, and code remain accurate.
This question comes from an official ITPEC past paper. ITPEC Practice is an independent study tool and is not affiliated with ITPEC. See the official FE past-paper collection or Report an issue.