🔒
Pro Content
Subscribe to access all 69 OCR H446 A Level lessons.
£7.99/month
or £59/year
Subscribe now →
🔒 Pro · Component 1 · 1.4.1 Data Types
1.4.1b Two's Complement, Binary Arithmetic and Hexadecimal
OCR H446 · A Level Computer Science · ~13 min read
Notes
Video
Slides
Worksheet
Quiz

Two's Complement — Representing Negative Numbers

Computers need to represent negative numbers. Two's complement is the most widely used method. In an n-bit two's complement system:

  • The most significant bit (MSB) is the sign bit: 0 = positive, 1 = negative
  • The MSB has a negative place value: for 8-bit, the MSB = −128
  • 8-bit two's complement range: −128 to +127
Bit 7 (MSB)Bit 6Bit 5Bit 4Bit 3Bit 2Bit 1Bit 0
−1286432168421

Method 1: Negating a Number (Flip and Add 1)

Find the two's complement of +42 (i.e. represent −42): +42 = 0010 1010
Step 1 — Flip all bits: 1101 0101
Step 2 — Add 1: 1101 0110
−42 in two's complement = 1101 0110

Check: −128+64+16+4+2 = −128+86 = −42 ✓

Method 2: Reading a Two's Complement Number

What is the denary value of 1011 0100 (two's complement)? MSB = 1 → negative number.
−128 + 32 + 16 + 4 = −128 + 52 = −76

Range of Two's Complement

Bit widthMinimumMaximumRange
8-bit−128+127−2⁷ to 2⁷−1
16-bit−32768+32767−2¹⁵ to 2¹⁵−1
32-bit−2,147,483,648+2,147,483,647−2³¹ to 2³¹−1

For an n-bit two's complement system: range = −2^(n−1) to 2^(n−1)−1.

Binary Addition

Binary addition follows the same column-by-column method as denary, with carries:

ABCarry inSumCarry out
00000
01010
11001
11111
Add 0011 1010 + 0101 1001: 0011 1010
+ 0101 1001
----------
1001 0011

Check: 58 + 89 = 147 = 1001 0011 ✓

Overflow

Overflow occurs when the result of an arithmetic operation is too large (or too small) to be stored in the available number of bits.

  • For unsigned 8-bit: overflow when result > 255 (carry out of bit 7)
  • For signed 8-bit two's complement: overflow when adding two positives gives a negative result, or two negatives give a positive result
Overflow example (8-bit signed): +100 + +80 0110 0100 (100)
+ 0101 0000 (80)
----------
1011 0100 → reads as −76 in two's complement. OVERFLOW! (two positives give negative)

Binary Subtraction Using Two's Complement

Subtraction is performed by adding the two's complement of the subtrahend: A − B = A + (−B)

Calculate 75 − 50 using two's complement (8-bit): +75 = 0100 1011
+50 = 0011 0010 → two's complement (−50) = 1100 1110

0100 1011
+ 1100 1110
----------
1 0001 1001 → carry out of bit 7 discarded → 0001 1001 = 25 ✓

Binary Shifts

Shifting a binary number left or right multiplies or divides by powers of 2:

  • Logical left shift by 1: multiply by 2. Shift all bits left, fill right with 0. MSB lost.
  • Logical right shift by 1: divide by 2 (integer division). Shift all bits right, fill left with 0. LSB lost.
  • Arithmetic right shift: preserves sign bit. Fills left with sign bit (0 for positive, 1 for negative) — maintains sign.
Logical left shift 0001 0110 (=22) by 2 positions: 0001 0110 → 0101 1000 = 88 = 22 × 4 ✓ (shifted left 2 = multiply by 2² = 4)
Exam tip: Two's complement range for n bits: −2^(n−1) to +2^(n−1)−1. For 8 bits: −128 to +127. The minimum (most negative) is 1000 0000 = −128. Zero is 0000 0000. +127 is 0111 1111.
Exam tip: To negate a two's complement number — flip all bits, add 1. This works in both directions (positive to negative AND negative to positive). Always check: +X + (−X) should give 0 (with carry discarded for 8-bit).
⚠ Common Mistakes
  • Forgetting that the MSB has place value −128 (not +128) in two's complement — if MSB=1, the number is negative.
  • Misidentifying overflow — overflow in signed arithmetic occurs only when the sign of the result is wrong (two positives add to give negative, or two negatives add to give positive). A carry out alone doesn't indicate signed overflow.
  • Forgetting to discard the carry when performing subtraction via two's complement — the 9th bit carry out is discarded for 8-bit arithmetic.
✓ Notes completed!
Video coming soon
Click to advance · Arrow keys also work
Click slide or press arrow keys to navigate

Worksheet — 1.4.1b Two's Complement & Binary Arithmetic

8 questions · 20 marks · instantly marked

Q1Represent −53 in 8-bit two's complement binary. Show all steps.[3 marks]
✓ Mark scheme
+53 in binary = 0011 0101 [1]; Flip all bits: 1100 1010 [1]; Add 1: 1100 1011 [1]. Check: −128+64+8+2+1 = −128+75 = −53 ✓. Answer: 1100 1011.
Q2What is the denary value of the 8-bit two's complement number 1001 0110? Show your working.[2 marks]
✓ Mark scheme
MSB = 1 → negative. −128 + 16 + 4 + 2 = −128 + 22 = −106 [2 — 1 for correct identification of negative, 1 for correct value].
Q3State the range of values that can be stored in 8-bit two's complement. What is the binary representation of the maximum and minimum values?[3 marks]
✓ Mark scheme
Range: −128 to +127 [1]; Minimum −128 = 1000 0000 [1]; Maximum +127 = 0111 1111 [1].
Q4Perform the binary addition 0110 1001 + 0011 0111. Show your working. State whether overflow has occurred in a signed 8-bit system.[4 marks]
✓ Mark scheme
0110 1001 (105) + 0011 0111 (55): column-by-column addition with carries [1]; Result = 1010 0000 [1]; In denary: 105+55=160, but 1010 0000 in two's complement = −128+32 = −96 [1]; Overflow HAS occurred — two positive numbers added to give a negative result (bit 7 changed from 0 to 1 unexpectedly) [1].
Q5Calculate 90 − 35 using 8-bit two's complement arithmetic (add the two's complement of 35 to 90). Show all steps.[4 marks]
✓ Mark scheme
+90 = 0101 1010; +35 = 0010 0011 [1]; Two's complement of 35: flip = 1101 1100, +1 = 1101 1101 [1]; Add: 0101 1010 + 1101 1101 = 1 0011 0111 [1]; Discard carry → 0011 0111 = 32+16+4+2+1 = 55 [1]. Check: 90−35=55 ✓
Q6Explain what is meant by overflow in binary arithmetic, and describe when it occurs in a signed 8-bit two's complement system.[3 marks]
✓ Mark scheme
Overflow occurs when the result of an arithmetic operation is too large or too small to be represented in the allocated number of bits [1]. In 8-bit signed two's complement, overflow occurs when: two positive numbers are added and the result has a 1 in the MSB (appears negative) [1]; or two negative numbers are added and the result has a 0 in the MSB (appears positive) — indicating the result is outside the range −128 to +127 [1].
Q7Perform a logical left shift by 2 on the binary number 0001 0011. What is the result in denary? What arithmetic operation does this correspond to?[3 marks]
✓ Mark scheme
0001 0011 shifted left 2 = 0100 1100 [1] (each bit moves 2 positions left, fill with 0s from right, MSBs discarded); Denary: 64+8+4 = 76 [1]; The original 0001 0011 = 19; 19 × 4 = 76 — a logical left shift by 2 is equivalent to multiplication by 2² = 4 [1].
Q8Why is two's complement preferred over sign-magnitude for representing negative numbers in computers?[2 marks]
✓ Mark scheme
Two's complement has a single representation for zero (0000 0000), whereas sign-magnitude has both +0 (0000 0000) and −0 (1000 0000) — the same value stored two ways causes complications [1]. Two's complement allows the same hardware adder circuit to handle both addition and subtraction — subtraction is performed by adding the two's complement, requiring no separate subtraction circuit [1].
Topic Quiz
1 of 15
You scored
out of 15
🎯

Mini Test — 1.4.1b Two's Complement

  • 10 questions · 10 marks · 10 minutes
  • 5 MCQ + 5 short answer
Card 1 of 15
Click to reveal
🎉
Complete!
TermDefinition
← 1.4.1a Primitive Data Types 1.4.1 Data Types Next: 1.4.1c Floating Point →