Y10 01 P5 Slides v2
Y10 01 P5 Slides v2
Learning objectives
In this lesson you will learn to:
For more detail on this topic, and additional student activities, refer to
Topic 2 of the student book.
© Pearson Education Ltd 2020. Copying permitted for purchasing institution only.
Y10-01-P5: Two’s complement (1)
Unsigned integers
Up to now, you have been working with unsigned integers.
These are whole numbers that are positive (0 or higher).
© Pearson Education Ltd 2020. Copying permitted for purchasing institution only.
Y10-01-P5: Two’s complement (1)
Negative numbers
Computers cannot recognise the symbols ‘+’ or ‘-’.
These need to be represented in binary in some way.
One method is to replace the most significant bit (MSB) with a sign
bit.
This means that the leftmost bit will be 0 for positive numbers and 1
for negative numbers.
This method of representing signed numbers is called sign and
magnitude.
What would these binary numbers be in denary using this method?
1000 0000
What might the problems be with this method?
© Pearson Education Ltd 2020. Copying permitted for purchasing institution only.
Y10-01-P5: Two’s complement (1)
An alternative…
Another method is called two’s complement.
The most significant bit is a minus number as well as a sign bit.
–128 64 32 16 8 4 2 1
1 0 0 0 1 1 0 1
-128 8 4 1 = –115
© Pearson Education Ltd 2020. Copying permitted for purchasing institution only.
Y10-01-P5: Two’s complement (1)
Conversion method
In two’s complement, positive numbers are the same as normal.
Example:
–128 64 32 16 8 4 2 1
0 0 0 0 0 1 1 1
4 2 1 = +7
IMPORTANT
Note that the answer is +7, not just 7
This is important as this is a signed integer.
It must have the sign present.
© Pearson Education Ltd 2020. Copying permitted for purchasing institution only.
Y10-01-P5: Two’s complement (1)
Conversion method
In two’s complement, negative numbers look quite different from their
unsigned equivalents.
Example:
–128 64 32 16 8 4 2 1
1 1 1 1 1 0 1 1
-128 64 32 16 8 2 1 = -5
0 0 0 0 0 1 0 1
4 1 = +5
© Pearson Education Ltd 2020. Copying permitted for purchasing institution only.
Y10-01-P5: Two’s complement (1)
Conversion method
You’ve looked at binary to denary conversions for two’s
complement, but how do you go back the other way?
For positive numbers, it’s just the same as you’ve done previously
using subtraction.
© Pearson Education Ltd 2020. Copying permitted for purchasing institution only.
Y10-01-P5: Two’s complement (1)
Worked Example
Let’s take the number -22 and convert it into binary using two’s
complement.
© Pearson Education Ltd 2020. Copying permitted for purchasing institution only.
Y10-01-P5: Two’s complement (1)
© Pearson Education Ltd 2020. Copying permitted for purchasing institution only.