|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Integers: signed
magnitude |
|
|
|
|
Signed magnitude |
|
|
|
|
Reserve one particular
bit for the sign. |
|
|
|
Sign bit: If msb is 0,
then positive value, if msb is 1, then negative value. |
|
|
Converting base 10 to
N-bit signed magnitude (SM): |
|
|
|
1. Ignoring sign, convert
base 10 value to binary. |
|
|
|
2. If less than (N-1)
bits, pad rest of bits to (N-1) with 0. |
|
|
|
3. If negative, set msb
to 1. |
|
|
|
Converting N-bit SM to
base 10: |
|
|
|
|
1. Convert lower (N-1)
bits to base 10. |
|
|
|
2. If msb is 1, put minus
sign in front of number. |
|
|
Example: |
|
|
|
|
Convert 3 in base 10 to
4-bit SM: |
|
|
|
|
binary value: 11 |
|
|
|
|
using 3 bits: 011 |
|
|
|
|
with sign bit: 0011 |
|
|
|
|
Convert -3 in base 10 to
4-bit SM: |
|
|
|
|
binary value: 11 |
|
|
|
|
using 3 bits: 011 |
|
|
|
|
with sign bit: 1011 |
|
|
|
|
What about 15? |
|
|
|
|
|
binary value: 1111 |
|
|
|
|
However, this is already
4 bits, and the sign bit needs to be 0 for positive value. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|