Lecture 8 Sign/Magnitude Addition and Subtraction Flashcards
What is sign extension?
Computers perform sign extension to ensure consistent bit lengths for arithmetic operations while preserving value.
How is sign extension done in sign/magnitude representation?
Pad the number with 0’s after the sign bit until the desired length is reached.
What is the algorithm for addition in sign/magnitude representation?
- Determine signs of operands.<br></br>2. If signs are the same, add magnitudes.<br></br>3. If signs differ, subtract smaller magnitude from larger and keep sign of larger.
How is subtraction performed in sign/magnitude representation?
Flip the sign bit of the subtrahend and perform addition.
What is an example of sign extension in sign/magnitude?
Extending 0b1011 (4 bits) to 10 bits:<br></br>Sign: 1, Magnitude: 011 → Extended: 0b1000000011.
What issue exists with sign/magnitude representation?
The existence of both +0 and -0 leads to inefficiencies.
What is one’s complement representation?
A number format where the most significant bit is the sign bit, and negation is done by flipping all bits.
How do you convert -16 to one’s complement (6-bit)?
Write +16 in binary: 0b010000, then flip all bits: 0b101111.
What is two’s complement representation?
A format where negation is done by flipping bits and adding 1, removing the problem of ±0.
How do you find the two’s complement of a number?
Negate all bits and add 1: \( \text{Two’s complement} = \text{One’s complement} + 1 \).
What is an example of two’s complement conversion?
Convert -16 to 5-bit two’s complement:<br></br>+16 = 0b10000, flip bits: 0b01111, add 1: 0b10000.
What happens when adding in two’s complement?
Addition works naturally, but overflow can occur if the result is out of range.
How do you perform subtraction in two’s complement?
Convert subtraction into addition: \( C = A - B = A + (-B) \), then use normal binary addition.
What is sign extension in two’s complement?
Extend the sign bit (MSB) to match the required bit length.
What is an example of sign extension in two’s complement?
Sign extend 0b1101 (4-bit) to 8-bit:<br></br>0b1101 → 0b11111101.
Why is two’s complement preferred in hardware?
It simplifies arithmetic operations and eliminates the need for extra processing logic.