Convert between decimal, binary and hexadecimal for 8‑bit signed integers.
Represent positive and negative numbers using two’s‑complement.
Perform binary addition, subtraction and detect overflow.
Apply logical left‑ and right‑shifts and understand their arithmetic effect.
Use overflow detection as a simple form of error‑checking (AO3).
1. Number‑system basics (Topic 1.1)
1.1 Decimal ↔ Binary (positive numbers)
Repeated division by 2 gives the binary digits (remainders). Pad the result with leading 0’s to obtain an 8‑bit pattern.
45 ÷ 2 = 22 r 1
22 ÷ 2 = 11 r 0
11 ÷ 2 = 5 r 1
5 ÷ 2 = 2 r 1
2 ÷ 2 = 1 r 0
1 ÷ 2 = 0 r 1 → binary 101101 → 8‑bit 00101101
1.2 Decimal ↔ Hexadecimal (positive numbers)
Convert the decimal number to binary, group the bits into nibbles (4‑bit groups) and replace each nibble by its hex digit.
45₁₀ → 0010 1101₂ → 2D₁₆
Conversely, to go from hexadecimal to decimal, expand each hex digit to its 4‑bit binary form and then evaluate the binary value.
1.3 Binary ↔ Hexadecimal (quick check)
Binary 1010 1100 → nibble 1010=A, 1100=C → AC₁₆.
Hex 7F → binary 0111 1111.
1.4 Simple 8‑bit addition and overflow detection (Topic 1.2)
When two 8‑bit numbers are added, any carry out of the most‑significant bit (MSB) is discarded. Overflow occurs when the carry into the sign bit differs from the carry out of the sign bit.
In an 8‑bit two’s‑complement word the most‑significant bit (MSB) is the sign bit. The representable range is
–2⁷ … 2⁷‑1 = –128 to 127
2.2 Positive numbers
Write the decimal value in binary.
Pad with leading 0’s to 8 bits (the sign bit is 0).
2.3 Negative numbers – conversion algorithm
Write the absolute value N in 8‑bit binary.
Invert every bit (one’s complement).
Add 1 to the result.
The final 8‑bit pattern is the two’s‑complement representation of –N. The sign bit is 1.
2.4 Why addition and subtraction work automatically
Addition: Adding a number to its two’s‑complement negative yields 00000000 (the final carry is discarded).
Subtraction: To compute A – B, add A to the two’s‑complement of B. The hardware performs only addition.
45 – 23
00101101 (+45)
+ 11101001 (‑23) ← two’s‑complement of 23
------------
00010110 (+22) ← correct result, no overflow
2.5 Overflow detection (AO3)
After an 8‑bit addition, examine the two carries around the sign bit:
If they are different → overflow (the true result is outside –128 … 127).
If they are the same → the result is valid.
In programmes this test is used to flag arithmetic errors before using the result.
2.6 Logical shifts (Topic 1.3)
Logical left shift (<< n): move all bits n places left, inserting 0’s on the right. Effectively multiplies the unsigned value by 2ⁿ (mod 256). For signed two’s‑complement numbers the sign bit may change, so overflow can occur.
Logical right shift (>> n): move all bits n places right, inserting 0’s on the left. Equivalent to floor division by 2ⁿ for unsigned values; for signed numbers it performs an arithmetic right shift only if the sign bit is replicated (not required for this syllabus).
Left shift: 00110101 (53) << 1 → 01101010 (106)
Right shift: 01101010 (106) >> 1 → 00110101 (53)
4. Conversion table (selected values)
Decimal
8‑bit Two’s‑Complement
Hexadecimal
-128
10000000
80
-100
10011100
9C
-64
11000000
C0
-45
11010011
D3
-23
11101001
E9
-1
11111111
FF
0
00000000
00
1
00000001
01
15
00001111
0F
23
00010111
17
45
00101101
2D
64
01000000
40
85
01010101
55
100
01100100
64
127
01111111
7F
5. Practice exercises
Write the 8‑bit two’s‑complement representation for:
+23
–23
+85
–85
+0
–0 (trick question)
Given the 8‑bit pattern 11101010, state the decimal value it represents in two’s complement.
Show, using binary addition, that adding 45 and –45 yields 0 (discard the final carry).
Demonstrate what happens when you add 1 to +127 in 8‑bit two’s complement, and indicate whether overflow has occurred.
Perform a logical left shift on 00110101 and give the decimal result.
Calculate 45 – 23 using two’s‑complement subtraction and state whether overflow occurs.
6. Common mistakes to avoid
Forgetting to pad positive numbers with leading 0’s to reach 8 bits.
Inverting bits **after** adding 1 – the correct order is invert first, then add 1.
Assuming 10000000 represents –0; in two’s complement there is only one zero: 00000000.
Using sign‑magnitude or excess‑bias methods when the question explicitly asks for two’s complement.
Ignoring overflow: adding two numbers that exceed the –128 … 127 range wraps around and changes the sign.
Treating a logical left shift as a safe multiplication – it can cause overflow and change the sign bit.
7. Summary
Two’s complement provides a single binary format for signed integers. In an 8‑bit system the sign bit is the MSB and the range is –128 to 127. Positive values are written directly; negative values are obtained by inverting the magnitude and adding 1. The same adder circuitry can perform addition, subtraction (by adding the two’s‑complement of the subtrahend) and logical shifts. Overflow is detected by comparing the carry into and out of the sign bit, a technique useful for simple error‑checking in programmes. Mastery of these conversions underpins all low‑level programming and debugging tasks required by the Cambridge IGCSE 0478 syllabus.
8. Further reading (Cambridge syllabus cross‑references)
Topic 1.1 – Number systems (binary, decimal, hexadecimal).