CompOrg Fall 2003

Number Representation and Arithmetic and C Logic

Due Date: 9/8/03 (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
567  
-567  
  0000111100001111
  1111000011110000

 

Decimal 16 bit unsigned binary 16 bit Hexadecimal
(4 hex digits)
65535    
  0001001000110010  
    FFEE

 

Decimal Floating Point IEEE Single Precision
Sign (1 bit) Exponent (8 bits) Significand (23 bits)
18.5      
  1 10000101 10000000100000000000000
 
Problem #2
 

Do Problem 2.43 from the textbook. Make sure that your answers are valid C expressions using only bitwise logical and logical operators!.

C bitwise logical operators:
&   |   ~   ^  
C logical operators:
&&   ||   !

Notes:

  • All we want is C expressions, not entire C programs. For example, an expression that determines whether the LS bit of x is a 1 is x & 0x01. This expression could be used as a boolean value in a C program, the expression is true only when the LS bit of x is a 1.
 
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).