SSD 06 Practical Quiz 1個人解答


この問題はExercise 02と何の違いもありませんが、ここで私の解答を出して、もう余計なことは言いません.
Introduction
The purpose of this assignment is to become more familiar with bit-level representations and manipulations. As with the Data Lab, you'll do this by solving a small number of programming "puzzles."
Getting Started
Download and unzip dlabp-handout.zip to a directory in which you plan to do your work. This will cause the following files to be unpacked into the directory:
bits.c
The data puzzles that you will solve. This is the file you will be modifying and handing in.
dlabp.vcproj
Project file
README
Helpful information about the lab
btest.c btest.h decl.c test.c getopt.c bits.h getopt.h tailor.h
The test driver and its helper files
Open the dlabp.vcproj workspace from VC++ and you are ready to begin solving your puzzles. You can add this project to a pre-existing (or new) VC++.Net Solution
Your Task
The only file you will be modifying and turning in is bits.c . Looking at bits.c you'll notice a C structure called info into which you should insert your name and login ID. Do this right away so you don't forget, as the driver will not run without it.
The bits.c file also contains a skeleton for each of the 4 programming puzzles. As before, your assignment is to complete each function skeleton using only straightline code (i.e., no loops or conditionals) and a limited number of C arithmetic and logical operators. Specifically, you are only allowed to use the following eight operators:
 ! ~ & ^ | + << >>

A few of the functions further restrict this list. See the comments in bits.c for detailed rules and a discussion of the desired coding style.
The enclosed dlabp.vcproj project will help you compile your bits.c file, along with the other helper functions, and link them all together to form the executable driver program btest.exe . The btest.exe driver program allows you to evaluate the functional correctness of your code. Every time you modify one of the puzzles in bits.c , you can check its correctness by rebuilding and rerunning btest.exe .
Puzzles
The following table describes the 4 puzzles that you will be solving in bits.c . The ``Rating'' field gives the difficulty rating (the number of points) for the puzzle, and the ``Max ops'' field gives the maximum number of operators you are allowed to use to implement each function.
Name
Description
Rating
Max Ops
tmin()
Returns the minimum two's complement integer
1
4
minusFive()
Returns the integer value -5
1
4
copyLSB(x)
Sets all bits of result to least significant bit of x
2
5
getBit(x, n)
Extract bit n from word x
2
4
See the bits.c file for examples of the results returned by these functions.
Evaluation
Your score will be computed out of a maximum of 12 points based on the following distribution:
6
Correctness of code as reported by btest.exe (no credit for a puzzle if your instructor determines that you have used an illegal operator).
4
Performance of code, based on number of operators used in each function (maximum of 1 point per puzzle).
2
Style points, based on your instructor's subjective evaluation of the quality of your solutions and your comments.
The puzzles you must solve have been given a difficulty rating between 1 and 2, such that their weighted sum totals to 6. Your instructor will evaluate your functions using the same btest.exe driver that you are using. You will get full credit for a puzzle if it passes all of the tests performed by btest.exe , half credit if it fails one test, and no credit otherwise. You receive no credit if you use an illegal operator for your solution, so pay close attention to the list of allowed operators for each puzzle in bits.c .
As before, we've established a maximum number of operators that you are allowed to use for each function. You will receive one point for each function that satisfies the operator limit.
Finally, we've reserved two points for a subjective evaluation of the style of your solutions and your commenting. Your solutions should be as clean and straightforward as possible. Your comments should be informative, but they need not be extensive.
Advice
  • Read the file README for information on running the btest.exe program.
  • You'll find it helpful to work through the functions one at a time, testing each one as you go. You can use the -f flag to instruct btest.exe to test only a single function. For example, "btest.exe -f bitAnd ".
  • The "-g "flag is very handy for producing a concise summary of your correctness results. For example, "btest -g ".
  • btest.exe is a console application, so you'll need to run it from the Windows command line. On a Windows 2000 system, you can find this at "Start->Accessories->Command Prompt". If you try to run it using "Start->Run.."instead, you won't see any of the output.

  • Hand In Instructions
    Before submitting your solution:
  • Make sure you have included your identifying information in your file bits.c .
  • Remove any extraneous print statements that you might have included for debugging.