Number Representation
Tom Kelliher, CS 220
Oct. 10, 2005
Study for exam.
Instruction formats, program build process.
- Introduction.
- Sign-magnitude, one's complement, and two's complement
representations.
- Negation and sign extension.
First exam.
- Weighted, positional number systems:
- Digit weights.
- Digit positions within a number.
- Conventionally, a base
system uses
numerals (symbols).
Consider decimal. This really isn't the case. Why? How can we make it
so?
- Consider a four bit binary number:
. What does
contribute to the value of the number?
- Hexadecimal: For the sake of brevity, binary numbers are often
written in hexadecimal form, because of a direct conversion between the
two:
| Binary |
Hexadecimal |
| 0000 |
0 |
| 0001 |
1 |
| 0010 |
2 |
| 0011 |
3 |
| 0100 |
4 |
| 0101 |
5 |
| 0110 |
6 |
| 0111 |
7 |
| 1000 |
8 |
| 1001 |
9 |
| 1010 |
A |
| 1011 |
B |
| 1100 |
C |
| 1101 |
D |
| 1110 |
E |
| 1111 |
F |
Examples: convert 110101 to hex and AE to binary.
- MIPS registers are 32-bits. How do you store 4 in a register?
What is the range of unsigned values representable in the MIPS? In
general, with
-bits, how many unsigned values can we represent?
- What do we do about numbers that are too big? Fractions? The reals?
- What about negative values? How do we represent them?
How do we solve this in the decimal system?
The sign bit. Location within a word.
Msb is sign, remaining bits are magnitude.
- Problems with sign-magnitude representation:
- Multiple zero representations.
- Consider the algorithm for a + b:
if a and b are of the same sign
{
sign of sum = sign of a;
magnitude of sum = magnitude of a + magnitude of b;
}
else if magnitude of a > magnitude of b
{
sign of sum = sign of a;
magnitude of sum = magnitude of a - magnitude of b;
}
else
{
sign of sum = sign of b;
magnitude of sum = magnitude of b - magnitude of a;
}
Symmetric range.
Msb is sign bit.
- Positive values have same representation as for unsigned case.
- To compute the inverse, complement all the bits.
- Two 0s.
- Symmetric range.
- Addition may cause wraparound carries.
Again, msb is sign bit.
- Positive values have same representation as for unsigned case.
- To compute the inverse, complement all the bits and add 1.
- One 0.
- Asymmetric range: one more negative value.
- Negation:
- Two's complement is called by that name because
Obviously,
So:
Hence our algorithm for negating a two's complement number.
- Sign Extension:
- How do you place a 16-bit signed immediate into a
register?
- How do you load a signed byte into register?
- The sign extension algorithm.
- Load byte unsigned.
- How can this simple procedure preserve the value of a negative
number? Proof?
- Signed & unsigned comparison. Or, sometimes 1111 is less than 0000
and sometimes it's not.
Thomas P. Kelliher
2005-10-07
Tom Kelliher