| CS 354, version A Fall 2005 | Answer Key | |
| Exam 1 Solution | ||
|
No electronic devices may be used while taking this exam. Examples of devices not allowed are calculators, pagers, cell phones, wrist calculators/computers, laptop computers, pocket computers. Each student is allowed one 8.5 by 11 inch sheet of paper with handwritten notes. The notes may be on both sides of the paper. Show all work, and do any/all calculations on the exam. Extra scratch paper may not be used. |
Exam Score Q1 = _____ / 4 Q2 = _____ / 6 Q3 = _____ / 6 Q4 = _____ / 12 Q5 = _____ / 8 Q6 = _____ / 10 Q7 = _____ / 8 Q8 = _____ / 4 Total = _____ / 58 |
Question 1 (4 points)
For the run length encoding program you wrote (Assignment 1):
if the following string is the complete contents of a file
that is to be compressed (encoded) by the program,
how many character-sized items will be in the resulting
file?
aaaabbb?????xAnswer: 8
Question 2 (6 points)
A Unix command line appears as
% a.out start 1 stop 100Diagram
argc and argv
as they are given to a C program.
argc is 5
-----
argv ----->| --|---> "a.out"
-----
| --|---> "start"
-----
| --|---> "1"
-----
| --|---> "stop"
-----
| --|---> "100"
-----
Question 3 (6 points)
Write the output from this C program to the right
of the source code.
#include <stdio.h>
main()
{
int a = 3; ----------------------------
int b = 8; | b equals c
int c = 12; | pointers not the same
int *ap; | equal
int *bp;
int *cp;
ap = &a;
bp = &b;
cp = &c;
ap = bp;
*bp = *cp;
if ( b == c ) {
printf("b equals c\n");
} else {
printf("b does not equal c\n");
}
if ( bp == cp ) {
printf("pointers same\n");
} else {
printf("pointers not the same\n");
}
if ( (*ap) == c ) {
printf("equal\n");
} else {
printf("not equal\n");
}
return(0);
}
Question 4 (12 points)
Identify the six steps of the instruction fetch and execute cycle
in their proper order:
Question 5 (8 points)
Part A
What decimal value is represented by the 8-bit,
two's complement representation 11101100?
Answer: -20 This is a negative integer, so take the two's complement to find out its absolute value: 00010011 + 1 = 00010100 is 16+4= 20.Part B What is the 8-bit, two's complement representation for the decimal value 65?
Answer: 01000001 65 is 64+1 1000001 in binary. The two's complement value in 8 bits zero extends this by 1 bit.
Question 6 (10 points)
Part A
Give the decimal value 20.3 in base 4.
Show any repeating digits by placing a bar over those digits that repeat.
Following the given algorithm:
Q R
20/4 5 0
5/4 1 1
1/4 0 1 Therefore 20 (base 10) = 110 (base 4)
Again, following a given algorithm:
.3 * 4 1.2
.2 * 4 0.8
.8 * 4 3.2
.2 (and notice that it repeats the last 2 digits)
__
20.3 (base 10) is 110.103 (base 4)
(where only the 03 portion repeats)
This is 6 * 8^1 + 0 * 8^0 + 2 * 8^(-1) 48 + 0 + 2/8 Answer: 48 1/4 or 48.25
Question 7 (8 points)
Give the IEEE single precision floating point representation
(in hexadecimal) for the decimal value
-1026.75.
1026 is 1024 + 2 or 2^10 + 2 In binary, 10000000010 .75 is .11 in binary Put the 2 parts together to get 10000000010.11 * 2^0 Move the radix point 10 places to the left to get 1.000000001011 * 2^10 The exponent field is unsigned of 10+127 (or 9+128) 10001001 Putting the pieces into their fields (not representing the hidden bit): S E F 1 10001001 00000000101100000000000 Respacing to get hexadecimal easily: 1100 0100 1000 0000 0101 1000 0000 0000 0x c4805800
Question 8 (4 points)
Given n bits, what range of integers can be
represented in two's complement representation?
-(2^(n-1)) to + 2^(n-1) - 1