Negative Binary Numbers (OCR A Level Computer Science)
Revision Note
Author
James WoodhouseExpertise
Computer Science
Signed Binary Numbers
What are Signed Binary Numbers?
A binary number can be signed or unsigned:
Unsigned - used to represent positive binary numbers
Signed - used to represent both positive and negative binary numbers
We can use signed binary numbers to represent negative numbers using methods such as:
Sign & magnitude
Two's complement
Both of these methods use the Most Significant Bit (MSB) to represent whether the number is negative or positive:
If the MSB is 0, the number is positive
If the MSB is 1, the number is negative
Sign & Magnitude
Sign & magnitude binary numbers contain a:
Sign - This is when the MSB is used to represent whether the number is negative (1) or positive (0)
Magnitude - This is used to describe the rest of the bits after the MSB
Representing negative binary numbers using sign & magnitude
Binary to denary example
To convert a sign & magnitude binary number to denary, you need to:
Convert the number as normal from binary to denary (as described in Positive Binary number: Binary to Denary)
Apply the MSB at the end of the calculation
If the MSB is 1, the number is negative
If the MSB is 0, the number is positive
Converting sign & magnitude binary numbers to denary
Denary to binary example
To convert a denary number to a sign & magnitude binary number, you need to:
Identify whether the number is positive or negative
Convert the number to binary as normal (as described in Positive Binary Numbers: Denary to Binary)
If the number is negative, change the MSB to 1
MSB | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
---|---|---|---|---|---|---|---|
1 | 1 | 0 | 0 | 0 | 1 | 1 | 1 |
64 + 4 + 2 + 1 = 71
Apply a sign of 1 to make -71
Therefore the denary number -71 in binary is 11000111
A consequence of using a sign bit
The MSB purpose changes from representing a value to representing positive or negative
Losing the MSB halves the maximum size of the number that can be stored
However, as a benefit it makes it possible to represent negative numbers
Sign & magnitude number system
Worked Example
Convert the 8-bit sign and magnitude binary number 10001011 to denary.
How to answer this question:
Identify the sign bit: The MSB is 1, so the number is negative
Isolate the magnitude: We are left with 0001011 by removing the sign bit
Convert to denary: The binary number 0001011 converts to 11 in denary
Apply the sign: The MSB was 1, so the number is -11 in denary
Answer:
Answer that gets full marks
10001011 converts to -11 in denary
Two's Complement
Two's complement is a different method for representing negative binary numbers
Calculations on two's complement numbers are less computationally intensive
Method
Start with the absolute value of the number, in this case 12
Invert the bits so that all of the 1's become 0's and all of the 0's become 1's
Add 1
Representing two's complement binary numbers
The purpose of the MSB has changed; it now represents the negative starting point of the number, and the rest of the bits are used to count upwards from that number. For example using the binary number from the image above:
Begin counting at -16
Add 4 to make -12
Two's complement has a similar consequence to sign and magnitude as the maximum value of an 8-bit value is halved
Denary to binary example
To convert the denary number -24 to a two's complement binary number, you need to:
Convert the number to binary
-128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
---|---|---|---|---|---|---|---|
0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 |
Invert the bits
-128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
---|---|---|---|---|---|---|---|
1 | 1 | 1 | 0 | 0 | 1 | 1 | 1 |
Add 1 to the number
-128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
---|---|---|---|---|---|---|---|
1 | 1 | 1 | 0 | 1 | 0 | 0 | 0 |
You've read 0 of your 0 free revision notes
Get unlimited access
to absolutely everything:
- Downloadable PDFs
- Unlimited Revision Notes
- Topic Questions
- Past Papers
- Model Answers
- Videos (Maths and Science)
Did this page help you?