Number Systems & Binary Arithmetic — Free HKDSE ICT Study Notes
Number systems and binary operations appear in every HKDSE ICT paper — sometimes subtly (parity-bit error detection in MCQs), sometimes explicitly (binary arithmetic in structured questions). This cheatsheet covers what you must know: conversions, two’s complement, arithmetic operations, BCD, Gray code, and storage-size calculations.
If you can do every worked example below without checking, you’re exam-ready for this topic.
Binary ↔ Decimal ↔ Hexadecimal Conversions
The basics
| Base | Name | Digits |
|---|---|---|
| 2 | Binary | 0, 1 |
| 10 | Decimal | 0–9 |
| 16 | Hexadecimal | 0–9, A–F |
Hexadecimal digits A–F: A=10, B=11, C=12, D=13, E=14, F=15
Binary ↔ Decimal
Binary to decimal — multiply each bit by its position value (powers of 2, right to left).
Example: Convert 1101₂ to decimal
1 × 2³ = 8
1 × 2² = 4
0 × 2¹ = 0
1 × 2⁰ = 1
Sum = 8 + 4 + 0 + 1 = 13
Decimal to binary — repeatedly divide by 2, collect remainders bottom to top.
Example: Convert 25 to binary
25 ÷ 2 = 12 remainder 1
12 ÷ 2 = 6 remainder 0
6 ÷ 2 = 3 remainder 0
3 ÷ 2 = 1 remainder 1
1 ÷ 2 = 0 remainder 1
Read bottom to top: 11001₂
Verify: 16 + 8 + 0 + 0 + 1 = 25 ✓
Binary ↔ Hexadecimal
Group binary into 4-bit chunks (pad with leading zeros if needed). Map each chunk to a hex digit.
| Hex | Binary | Hex | Binary |
|---|---|---|---|
| 0 | 0000 | 8 | 1000 |
| 1 | 0001 | 9 | 1001 |
| 2 | 0010 | A | 1010 |
| 3 | 0011 | B | 1011 |
| 4 | 0100 | C | 1100 |
| 5 | 0101 | D | 1101 |
| 6 | 0110 | E | 1110 |
| 7 | 0111 | F | 1111 |
Example: Convert 11010110₂ to hexadecimal
1101 0110
↓ ↓
D 6
Result: D6₁₆
Example: Convert 3F₁₆ to binary
3 → 0011
F → 1111
Result: 0011 1111₂
Two’s Complement Signed Integers
Two’s complement is how computers represent negative numbers. The most significant bit (MSB) is the sign bit: 0 = positive, 1 = negative.
4-bit two’s complement range
A 4-bit two’s complement number can represent −8 to +7:
| Binary | Decimal | Binary | Decimal |
|---|---|---|---|
| 1000 | −8 | 0000 | 0 |
| 1001 | −7 | 0001 | 1 |
| 1010 | −6 | 0010 | 2 |
| 1011 | −5 | 0011 | 3 |
| 1100 | −4 | 0100 | 4 |
| 1101 | −3 | 0101 | 5 |
| 1110 | −2 | 0110 | 6 |
| 1111 | −1 | 0111 | 7 |
Finding the two’s complement
To negate a number: invert all bits, then add 1.
Example: Find −5 in 8-bit two’s complement
Step 1: Write +5 in binary: 0000 0101
Step 2: Invert bits: 1111 1010
Step 3: Add 1: 1111 1011
Result: −5 = 1111 1011₂
Ascending-order trap: In two’s complement, the binary order does not match magnitude order. For 4-bit, 1000₂ (−8) is less than 1111₂ (−1), but 1000₂ > 1111₂ numerically. Don’t sort signed binary numbers as if they were unsigned.
Binary Arithmetic
Addition
Same rules as decimal, base 2. Carry occurs when 1 + 1 = 10₂.
| A | B | Sum | Carry |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 1 |
Example: Add 1101₂ (13) and 1011₂ (11)
1101
+ 1011
------
11000₂
Verify: 13 + 11 = 24 ✓
Subtraction via two’s complement
Computers subtract by adding the negative. A − B = A + (−B) where (−B) is B’s two’s complement.
Example: Subtract 0101₂ (5) from 1010₂ (10)
A = 1010₂ (10)
B = 0101₂ (5)
Step 1: Two's complement of B
0101 → invert → 1010
1010 + 1 = 1011₂ (this is −5)
Step 2: Add A + (−B)
1010 + 1011 = 10101₂
Step 3: Discard overflow carry (leftmost bit)
101₂ = 5
Verify: 10 − 5 = 5 ✓
Overflow detection
In fixed-width arithmetic (e.g., 8-bit), the result might not fit. Overflow occurs when:
- Adding two positive numbers gives a negative result
- Adding two negative numbers gives a positive result
- Adding positive + negative never overflows
Example (4-bit): 0100₂ (+4) + 0101₂ (+5) = 1001₂ (−7 in two’s complement)
Result is negative, but both inputs were positive → overflow. The correct answer (+9) doesn’t fit in 4-bit two’s complement (range −8 to +7).
BCD and Gray Code
These are alternate binary representations, each with specific purposes.
BCD (Binary Coded Decimal)
BCD encodes each decimal digit separately using 4 bits.
| Decimal | BCD | Decimal | BCD |
|---|---|---|---|
| 0 | 0000 | 5 | 0101 |
| 1 | 0001 | 6 | 0110 |
| 2 | 0010 | 7 | 0111 |
| 3 | 0011 | 8 | 1000 |
| 4 | 0100 | 9 | 1001 |
Example: Convert 259 to BCD
2 → 0010
5 → 0101
9 → 1001
Result: 0010 0101 1001 (BCD)
BCD is NOT the same as pure binary: 259₁₀ = 100000011₂ in pure binary, but 0010 0101 1001 in BCD.
When examined: BCD appears in questions about financial systems or displays where exact decimal representation matters (avoids floating-point rounding errors).
Gray Code
Gray code ensures only one bit changes between consecutive values. This prevents brief invalid states in hardware (encoders, sensors).
Binary → Gray: MSB stays same; each subsequent bit = XOR of current binary bit and previous binary bit.
Example: Convert 1011₂ to Gray code
Binary: 1 0 1 1
Gray MSB: 1 (same)
Bit 2: 1⊕0 = 1
Bit 3: 0⊕1 = 1
Bit 4: 1⊕1 = 0
Result: 1110 (Gray)
When examined: Gray code appears in questions about rotary encoders, Karnaugh maps, or error-resistant signal transmission.
Storage-Size Questions
These questions ask: What’s the minimum storage needed for N distinct values?
Formula
For N distinct values, minimum bits n where 2ⁿ ≥ N.
Then round UP to whole bytes (1 byte = 8 bits).
Worked example: RFID tag
Question: An RFID system needs to uniquely identify 500 items. What’s the minimum storage required?
Step 1: Find minimum bits
2⁸ = 256 (not enough)
2⁹ = 512 (enough)
Minimum bits = 9
Step 2: Round up to bytes
9 bits ÷ 8 = 1.125 bytes
Round UP = 2 bytes
Answer: Minimum 2 bytes (16 bits). This can represent 65,536 unique IDs — far more than the 500 required, but storage comes in byte-sized chunks.
Common pattern in past papers
Questions like DSE 2015 Paper 1 Q5 (RFID tag storage) test this exact formula: find 2ⁿ ≥ N, then round up to bytes.
Self-Check Questions
Test yourself. Answers are in the collapsible below.
- Convert
10110011₂to decimal and hexadecimal. - Find the 8-bit two’s complement representation of −42.
- Add
0110₂and0101₂in binary. Does overflow occur in a 4-bit system? - Convert
38₁₀to BCD. - How many bytes are needed to store 2000 unique values?
Click for answers
- Decimal:
128 + 32 + 16 + 2 + 1 = 179| Hex: Group as1011 0011→B3₁₆ - −42 in 8-bit two’s complement:
+42 = 0010 1010→ invert →1101 0101→ add 1 →1101 0110₂ - Sum:
0110 + 0101 = 1011₂(decimal 11). No overflow — both inputs positive, result positive. - BCD:
3 → 0011,8 → 1000→0011 1000(BCD) - Bytes needed:
2¹⁰ = 1024(not enough),2¹¹ = 2048(enough) → 11 bits → round to 2 bytes
Want full notes and more practice?
This is a sample of our HKDSE ICT notes. The full set covers every syllabus topic with worked examples, past-paper patterns, and exam technique.
Explore our complete HKDSE ICT notes — structured for revision, optimized for exam day.
Need personal feedback? Book a trial lesson — we’ll review your answers, fix your misconceptions, and build your targeted study plan.