previous
 next 
CS 3843 Computer Organization
Notes on Chapter 2

Today's News: January 17
No recitations this week

Sections 2.2 and 2.2.1: Integer Representation

Section 2.2.2: Unsigned encodings

Section 2.2.3: Two's complement (and other) encodings


Today's News: January 22
Recitations start this week

Sections 2.2.4 and 2.2.5: Conversions between signed and unsigned

Most C compilers do this conversion by retaining the bit pattern without any checking for validity.

Section 2.2.6: Expanding the bit representation of a number

This refers to converting to a representation with more bits and occurs when you do something like assign a short to an int.
We will only consider the two's complement representation.

Section 2.2.7: Truncating numbers

Section 2.2.7 Example

Section 2.2.8: Advice on signed and unsigned numbers

Be careful when using expressions involving unsigned values.
Remember that an arithmetic operation involving a signed and unsigned value is converted to unsigned.
Example (almost from book):
int sum(int a[], unsigned length) {
   int i;
   int result = 0;
   for (i=0; i <= length-1; i++)
      result += a[i];
   return result;
}
How many times does this go through the loop when length is 0?

Signed and unsigned numbers

Figure 2.16 shows convesion from two's complement to unsigned.
t2u.jpg t2ub.jpg

Figure 2.17 shows conversion from unsigned to two's complement.
u2t.jpg u2tb.jpg