SSD06 Practical Quiz 1 个人解答

本文介绍了一项关于位级表示和操作的编程任务,通过解决四个特定的编程谜题来熟悉位级编程。任务包括使用有限的C语言算术和逻辑运算符实现直译代码,不允许使用循环或条件语句。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

这个题目和Exercise02 没什么区别,在这里把我的解答给出来,就不再赘述了。

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.

NameDescriptionRatingMax Ops
tmin() Returns the minimum two's complement integer14
minusFive() Returns the integer value -514
copyLSB(x) Sets all bits of result to least significant bit of x25
getBit(x, n) Extract bit n from word x 24

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:

6Correctness of code as reported by btest.exe
(no credit for a puzzle if your instructor determines that you have used an illegal operator).
4Performance of code, based on number of operators used in each function (maximum of 1 point per puzzle).
2Style 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.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值