Teachers' Portal  /  A-Level Computer Science 9618  /  Information representation  /  Two's complement and binary arithmetic
Lesson pack · A-Level Computer Science 9618 · 1.1 · AS Level

Two's complement and binary arithmetic

Negative numbers in binary. A register has no minus sign, so negative integers need a representation of their own.

Student lesson Lab, full screen
At a glance

The shape of the lesson

Topic
Information representation
Syllabus reference
Cambridge International AS and A Level Computer Science 9618, 1.1
Level
AS Level
Duration
45 minutes, lab-led; stretches to a 60 minute block (see the contingency notes)
Position in topic
Lesson 3 of 7 in Information representation; follows Binary, denary, hexadecimal and BCD; leads into Character sets: ASCII, extended ASCII and Unicode
Central model
Fig. 1: 11010011 in 8-bit two's complement is −45
Cooperative structure
Assessment
Stage 1 check and the exam-style plenary from the student lesson, plus the worksheet as the exit task
Learning objectives

By the end of the lesson, learners can

Section by section
  • One's and two's complement: In the lab's two's complement mode, set the bits and watch the leftmost one count as −128.
  • Subtract by adding: Switch the lab to subtraction.
  • When the result will not fit: Overflow happens when a calculation produces a value the register cannot represent.
Key points to leave on the board
  • Two's complement: leftmost place value is −128 in 8 bits; range −128 to +127.
  • Negate: invert every bit, then add 1 (inverting alone gives one's complement).
  • Subtract: A − B = A + (−B); ignore a carry out of the leftmost bit.
  • Overflow: two positives give a negative, or two negatives give a positive.
The core visual model

One picture every idea returns to

In two's complement the most significant bit has a negative place value: in 8 bits it is −128, so the range is −128 to +127. To negate a number, invert every bit (this alone gives the one's complement) and then add 1. Subtraction is done by adding the negative: A − B = A + (−B). Overflow occurs when the true result is outside the range: adding two numbers with the same sign gives a result with the opposite sign.

8-bit two's complement: the leftmost place value is negative −128643216 8421 1101 0011 −128 + 64 + 16 + 2 + 1 = −45 +45 = 00101101 invert: 11010010 add 1: 11010011 range in 8 bits: −128 to +127
Fig. 1: 11010011 in 8-bit two's complement is −45
Lesson sequence

Forty-five minutes, phase by phase

TimePhaseWhat happens in the roomGrouping
0 to 5 minHook: predictOpen with the question in the title, Negative numbers in binary.. A register has no minus sign, so negative integers need a representation of their own. Put the figure on the board: it is the one picture every idea in the lesson returns to.Whole class, then pairs
5 to 13 minTeach and check: One's and two's complementIn the lab's two's complement mode, set the bits and watch the leftmost one count as −128. Project tab 5 of the lab (Two's complement) and let a student drive it while the class predicts. Model the worked example Denary to two's complement on the board, one line at a time. Your turn: Write −100 in 8-bit two's complement.Whole class, then pairs
13 to 21 minTeach and check: Subtract by addingSwitch the lab to subtraction. Project tab 5 of the lab (Subtraction in two's complement) and let a student drive it while the class predicts. Model the worked example Negative answer on the board, one line at a time. Your turn: Calculate 38 − 91 in 8-bit two's complement.Pairs
21 to 30 minTeach and check: When the result will not fitOverflow happens when a calculation produces a value the register cannot represent. Project tab 3 of the lab (Binary addition and overflow) and let a student drive it while the class predicts.Numbered Heads Together
30 to 36 minCheckThe four Stage 1 questions from the student lesson, answered on mini whiteboards or by show of fingers. Re-teach the one most get wrong.Individual, then whole class
36 to 43 minPlenaryThe exam-style questions from Stage 2, one at a time: thirty seconds alone, then a random call. The feedback lines in the key give the examiner's wording.Individual, random call
43 to 45 minExit and homeworkSet the worksheet below (6 questions, 14 marks). Learners self-assess against the objectives before they leave.Individual
Timing and contingency

Protect the parts that carry the learning

The sequence carries about fifty minutes of material, so the lab is driven by one student while the class predicts rather than explored freely. Times are a guide.

Protected: the check at 30 minutes. It is the only individual read on whether the key idea landed, and it is not cut.

Cut first if the build overruns: the last check in When the result will not fit, never the check or the plenary.

In a 60 minute block: run worksheet questions 1 to 3 in class as a Rally Coach set and model both the hardest worked example and its check live.

Running the cooperative task

Numbered Heads Together

Teams of four number off. Put up a question, give the team time to make sure every member can answer, then call a number: that student answers for the team, so nobody can leave the thinking to someone else.

The full structure, with its variations and the other twelve, is on the cooperative-learning page.

Examiner traps to pre-empt

What to head off, and how

Trap learners fall intoTeaching move that pre-empts it
Inverting the bits is not the whole job for two's complement.Forgetting to add 1 gives the one's complement, which is out by one.
A carry out of the leftmost bit is not the test for overflow in two's complement.Check the signs: overflow only when two positives give a negative or two negatives give a positive.
Worksheet

Two's complement and binary arithmetic: worksheet

6 questions, 14 marks. Written in the style of the papers; no past paper question is reproduced.

NameClassDate
Q1 · convert[2 marks]

Convert the denary number −77 to 8-bit two's complement. Show your working.

Q2 · convert[1 mark]

The 8-bit two's complement integer 10101010 is stored. Give its denary value.

Q3 · calculate[3 marks]

Calculate 38 − 91 using 8-bit two's complement arithmetic. Show your working and give the answer in binary and denary.

Q4 · explain[3 marks]

The 8-bit two's complement integers 01011010 and 01000110 are added. Give the 8-bit result and explain what has happened.

Q5 · explain[3 marks]

State the range of integers that can be stored in 8 bits using (a) one's complement and (b) two's complement, and explain why the ranges differ.

Q6 · analysis[2 marks]

A 16-bit register holds the hexadecimal value FF9C, which is a two's complement integer. Give its denary value and show how you found it.

Answer key and marking notes
Q1 · 2 marks
  • +77 = 01001101, inverted 10110010.
  • Add 1: 10110011.
Q2 · 1 mark

−128 + 32 + 8 + 2 = −86.

Q3 · 3 marks
  • 38 = 00100110; −91 = 10100101 (01011011 inverted is 10100100, plus 1).
  • 00100110 + 10100101 = 11001011.
  • 11001011 = −128 + 64 + 8 + 2 + 1 = −53.
Q4 · 3 marks
  • Result 10100000.
  • The true answer is 90 + 70 = 160, which is above the maximum of +127.
  • Overflow: two positive numbers have given a negative result (−96).
Q5 · 3 marks
  • (a) −127 to +127.
  • (b) −128 to +127.
  • One's complement has two representations of zero (00000000 and 11111111), wasting one pattern; two's complement has only one zero, so it can represent one extra negative number.
Q6 · 2 marks
  • FF9C = 1111 1111 1001 1100; it is negative because the leftmost bit is 1.
  • Invert to 0000 0000 0110 0011 and add 1: 0000 0000 0110 0100 = 100, so the value is −100.
Quiz

6 multiple-choice questions on this lesson

From the topic question bank. Assign them in the app for a marked score in your gradebook, or run the topic as a class game.

Q11 mark

What is −45 in 8-bit two's complement?

  • A11010011
  • B11010010
  • C10101101
  • D00101101
Q21 mark

The 8-bit two's complement value 10110100 is stored. What is its denary value?

  • A−76
  • B180
  • C−52
  • D−75
Q31 mark

What is the range of integers that can be stored in 8-bit two's complement?

  • A−128 to +127
  • B−127 to +127
  • C−127 to +128
  • D0 to 255
Q41 mark

The calculation 52 − 75 is done by adding the 8-bit two's complement of 75 to 00110100. What bit pattern results?

  • A11101001
  • B00010111
  • C11101000
  • D10010111
Q51 mark

Which 8-bit two's complement addition produces an overflow?

  • A01110000 + 00100000
  • B11110000 + 11100000
  • C01010000 + 10110000
  • D10000001 + 01111111
Q61 mark

In 8-bit two's complement, 11111100 is added to 00000110. A 1 is carried out of the leftmost bit. Which statement is correct?

  • AThe stored result 00000010 (+2) is correct and the carry is ignored
  • BOverflow has occurred, so the stored result cannot be trusted
  • CThe true result is 100000010, which is 258
  • DThe stored result is −126 because the carry sets the sign bit
Quiz key
Q1: A

+45 = 00101101; inverting gives 11010010 and adding 1 gives 11010011 (check: −128 + 64 + 16 + 2 + 1 = −45). 11010010 is only the one's complement, 10101101 is sign and magnitude, and 00101101 is +45.

Q2: A

−128 + 32 + 16 + 4 = −76. 180 reads the pattern as unsigned binary, −52 treats the first bit as a plain sign (sign and magnitude), and −75 inverts the bits but forgets to add 1.

Q3: A

10000000 = −128 is the smallest value and 01111111 = +127 is the largest. −127 to +127 is the range of sign and magnitude, −127 to +128 puts the extra value on the wrong side, and 0 to 255 is unsigned binary.

Q4: A

−75 = 10110101; 00110100 + 10110101 = 11101001, which is −128 + 64 + 32 + 8 + 1 = −23. 00010111 is +23 (the sign has been lost), 11101000 is the one's complement form of −23, and 10010111 is −23 in sign and magnitude.

Q5: A

112 + 32 = 144, which is above +127; the register would hold 10010000 (−112), a negative from two positives. −16 + (−32) = −48 fits, even though there is a carry out of the leftmost bit. 80 + (−80) = 0 and −127 + 127 = 0 have opposite signs, so they can never overflow.

Q6: A

11111100 = −4 and 00000110 = +6, so the sum should be +2, which is exactly what the register holds. In two's complement a carry out of the leftmost bit is discarded and is not a sign of overflow; overflow needs two operands of the same sign. 258 treats the values as unsigned with a ninth bit, and the carry does not change the sign bit of the stored result.

Lab and demo

What to project

The student lesson embeds these tabs. Open them full screen on the projector; every slider has a drag handle on the stage.

Slides

Slides for this lesson

A projectable deck for every pack is on the way. Until then, present the student lesson full screen: its sections, figure and lab tabs follow the same order as the plan above.

Also for this topic

Everything else you can use

Original work by the TheLucidSTEM team. The worksheet items are written in the style of the papers; no past paper question is reproduced.
Previous lessonBinary, denary, hexadecimal and BCD