$\require{cancel}$
Sign Magnitude
- Why worry about 9's and 10's complement?
- Sign magnitude
- This is the way we normally work
- -3, +14, ...
- But as we saw last time, we have a rules based system for addition
- If the signs are the same, keep the sign and add the magnitudes
- Of the signs are different, subtract the smaller magnitude from the larger then keep the sign of the larger.
- If we have subtraction, change the sign of the second and turn it into an addition problem.
- Plus there is a problem with -0
- Consider a 3 bit representation in sign magnitude.
- The first bit (msb) is a sign bit, 0 => +, 1=> -
- What is 010?
- What is 000?
- What is 110?
- What is 100?
- There are (at least) two problems with sign magnitude
- -0
- The rules based addition.
- We do use sign-magnitude for floating point, which is coming soon.
- But
- The CPU does most of the work in integer
- So integer needs to be fast
- And 2's complement is faster than sign-magnitude for integer.
- On common misconception: you can represent fewer signed numbers than unsigned numbers with the same number of bits.
- This is not true (well mostly not true)
- With 4 bits, we have $2^4 = 16$ different patterns
- This means we can represent 16 different numbers.
- Unsigned we can represent 0-15 (or 0 to $2^{n-1})$
- Sign magnitude we can represent -7 to 7 (a total of 15).
- In one's complement there is a -0
- We will use two's complement from here on out.
- Let's do some math in 6 bit two's complement.
- First what are the ranges?
- $(-2^{6-1} to 2^{6-1} -1$
- Or -32 to 31
- 17 + 12
- 17 - 12
- -17 + 12
- -17 - -12