CompOrg Fall 2002 Homework #1

Number Representation and Arithmetic

Due Date: 9/12/02 (in class)
Hardcopy only (no electronic submissions)

Problem #1
 

Figure out the missing values in the tables below (all the blank cells). Pay attention to whether items are signed or unsigned, and the number of bits!.

Decimal 16 bit 2s complement binary
999  
-999  
  1010101010101010
  0101010101010101

 

Decimal 16 bit unsigned binary 16 bit Hexadecimal
(4 hex digits)
65535    
  0011001100110011  
    0ABC

 

Decimal Floating Point IEEE Single Precision
Sign (1 bit) Exponent (8 bits) Significand (23 bits)
12.125      
  1 10000001 01000000000000000000000
 
Problem #2
 

Do Problem 2.42 from the textbook: "Write a C expression that will yield a word consisting of the least significant byte of x and the remaining bytes of y. For operands x = 0x89ABCDEF and y = 0x76543210, this would yield 0x765432EF."

Notes:

  • Assume that a word is 32 bits.
  • You need need to use logic operations (AND, OR, ...).
  • All we want is an expression, not an entire C program. For example, an expression that yields the sum of two integers x and y would be x+y.
 
Problem #3
 

Consider the computer addition of two integers. Both integers are representable as 8-bit 2's complement integers. The result is also an 8 bit 2's complement integer. We know that the true sum may not fit in an 8 bit 2's complement integer - your job is to write some C code that determines whether or not the answer is correct. You can't use any arithmetic that involves anything other than 8 bit 2's complement numbers, but you can use logic operations. Show some C code that will print "yes" if the computed sum is correct (the correct answer fits in an 8 bit 2's complement int) or prints "no" if the answer is wrong (the sum cannot be represented as an 8-bit 2's complement int).

Here is what the code might look like, with the sections you must write left out. NOTE: x,y and z are all signed 8 bit numbers (in C, declared as char)

/* x and y already have some values at this point */

z = x + y;   /* z now has 8 bit result. Is it right? */

if (...you need to write this...) {
   printf("yes");
} else {
   printf("no");
}

NOTE: Feel free to write it any way you want, you don't have to do the entire job with a single if statement as shown above.

HINTS: Review the conditions under which the result of 2's complement computer addition is not correct (page 70 in the text). You need to find a way to express these conditions in C, without using arithmetic (use logic operations - look at the bits of x,y and z).