OCR A-Level Computer Science H446
Processors: Structure, Performance and Types
Input, Output and Storage
Systems Software
Applications Generation
Software Development
Types of Programming Language
Exchanging Data
Networks
Web Technologies
Data Types and Number Representation
Data Structures
Boolean Algebra
Legal, Moral, Cultural and Ethical Issues
Elements of Computational Thinking
Problem Solving and Programming
Algorithms
Data Types and Number Representation
Negative numbers: sign and magnitude and two's complement
- 2 things to know
- Component 01
Overview
Recall questions on sign and magnitude and its two zeros, two's complement and the flip-and-add-one method, converting negative numbers both ways, ranges of each, subtracting with an adder, and sign extension.
What you need to know
Answer each one before you reveal it.
Give three reasons why two's complement is preferred to sign and magnitude.
Questions from this subtopic
Each one with the model answer underneath.
- 1
In sign and magnitude, how is a negative number represented?
Model answer
The leftmost bit is used purely as a sign flag, 0 meaning positive and 1 meaning negative, and all the remaining bits hold the size of the number as an ordinary positive binary value. The sign bit has no place value of its own; it is just a label saying which way to read the magnitude.
- 2
Write minus 37 as an eight-bit sign and magnitude number.
Model answer
10100101. The magnitude 37 in seven bits is 0100101, since 32 + 4 + 1 = 37. Putting a 1 in front as the sign bit to mark it negative gives 10100101.
- 3
What is the range of an eight-bit sign and magnitude number?
Model answer
Minus 127 to plus 127. Seven bits are left for the magnitude, and the largest seven-bit value is 1111111, which is 127. The sign bit then allows that magnitude either way.
- 4
What is the problem with zero in sign and magnitude?
Model answer
There are two representations of it. 00000000 is positive zero and 10000000 is negative zero, and they are the same number written two ways. This wastes a bit pattern, but worse, it means a test for zero has to check for two different patterns and a comparison of two values cannot simply compare their bit patterns, since the two zeros are equal in value but different in bits.
- 5
Add the sign and magnitude numbers 00000101 and 10000011 as though they were plain binary, and explain what goes wrong.
Model answer
The two numbers are plus 5 and minus 3, so the answer should be plus 2. Adding the bit patterns column by column gives 10001000, which reads as sign 1 and magnitude 0001000, that is minus 8. It is nonsense. The problem is that in sign and magnitude the sign bit is not part of the number's value, so it must not be added in, and the hardware instead has to compare the two magnitudes, decide which to subtract from which, and then work out the sign of the result separately. That extra logic is the main reason the representation is not used for arithmetic.
- 6
In two's complement, what is different about the leftmost bit?
Model answer
It is a genuine place value, but a negative one. In an eight-bit two's complement number the leftmost bit is worth minus 128, while all the other bits keep their normal positive place values of 64, 32, 16, 8, 4, 2 and 1. So the sign bit is part of the arithmetic rather than a separate flag, which is exactly why ordinary binary addition works on these numbers.
Other ways to work this
The same content, four other ways.
What is inside Levo
Six ways to work the same material.
Every question in Data Types and Number Representation, on a schedule.
Attempt a question from memory, write the correct version, then attempt it again. Levo records the jump between your first attempt and your last, and brings each question back on the day you are due to forget it.
Or £46 a year, about £3.83 a month. Cancel anytime.