Two's Complement
Course Content Specification
Describe and exemplify the use of binary to represent positive and negative integers using two’s complement, including the range of numbers that can be represented using a fixed number of bits.
Conversion of two’s complement numbers from binary to denary and vice versa.
Two's Complement Notation
So far we have looked how to store positive integers, but we need to be able to also store negative integers. The method we will look at to store negative integers is called two’s complement.
Creating a Two's complement number
Create the positive number ( a reminder is here if needed)
Invert all the 0’s to 1’s and all the 1’s to 0’s
Add 1 to the RIGHT of the number. (Sometimes called the Least Significant Bit)
Tutorial Video
![](https://www.google.com/images/icons/product/drive-32.png)
When a binary number is represented in 2’s complement the MSB (Most Significant Bit) which is the left most bit functions as a sign bit.
A negative two's complement number will being with a 1
A positive two's complement number will begin with a 0
Examples:
1001 1010 = -102
0111 1110 = +126
Worked Example 1 - Negative 25
Create the positive number (25): 0001 1001
Invert all the 0’s to 1’s and all the 1’s to 0’s: 1110 0110
Add 1 to the RIGHT of the number. (Sometimes called the Least Significant Bit)
Worked Example 2 - Negative 36
Create the positive number (36) 0010 0100
Invert all the 0’s to 1’s and all the 1’s to 0’s: 1101 1011
Add 1 to the RIGHT of the number.
Converting a Two's Complement number to decimal
If you are given a negative number which is already in two’s complement and you need to find out what value it is simply carry out the same conversion steps again.
Example:
1111 0111(-9) (in this case we know that the answer is 0000 1001 = 9 what we aim to get)
Invert all the 0’s to 1’s and all the 1’s to 0’s.
0000 1000
Add 1 to the RIGHT of the number.
0000 1001 - This tells us that we started off with +9 so the two's complement version is -9.
Another Method of Converting
If we want -10 in 8 bit two’s complement find the positive version: 0000 1010
Work from right to left
Find the first 1 on the right hand side - that and everything to the right of it stays the same
invert everything to the left of the first 1 so the bits below in bold stays the same.
Range of Representation
Highest Numbers
The maximum positive number that can be represented when using twos complement is when the MSB ( the left hand bit) is 0 and all remaining bits are 1.
E.g. 8 bit = 0111 1111 (+127)
16 bit = 0111 1111 1111 1111 (+32,767)
Lowest Numbers
The lowest negative number that can be represented when using twos complement is when the MSB is 1 and all remaining bits are 0
8 bit = 1000 0000 (-128)
16 bit = 1000 0000 0000 0000 (-32,768)
Place values in Two's Complement
It is exactly the same as earlier except the most significant bit is a negative value. If we look at an 8 bit two’s complement number such as 1111 0111 (-9)
You should notice that the right hand bit is (-27) which is (-2n-1) where n is the number of bits.
And -9 = -128 + 64 + 32 +16 + 4 + 2 + 1
So the range is from -2n-1 to + (2n-1) -1
where n is the number of bits that you are using (usually 8 or 16 in exams)
How do you know if a number is negative?
We don’t!
Data in memory is just data, it depends on the instructions used by the processor (influenced by things such as data types etc) to control how data is manipulated.
1111 0111 could be -9 or 247, or a pixel in a bitmap.
But different instructions would control whether the processor interpreted it as a signed number, unsigned number or a pixel in a bitmap. This will control how things such as overflow and carry operations are carried out. The same as if you are lifting a wardrobe and a cup you would have to ‘lift’ each one differently.
What about in exams?
In exams if you are looking at a number in two's complement notation remember that if the left hand bit is a 1 it is a negative number and if it is 0 it is positive.
Test Yourself
Convert the number -54 using 8 bit two's Complement notation
11001010
Convert the number -104 using 8 bit two's Complement notation
10011000