DOC PREVIEW
Harvey Mudd CS 105 - CS 105 Lab 1: Manipulating Bits

This preview shows page 1-2 out of 5 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 5 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 5 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 5 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CS 105Lab 1: Manipulating BitsSee class calendar for lab and due datesIntroductionThe purpose of this assignment is to become more familiar with bit-level representations and manipulations.You’ll do this by solving a series of programming “puzzles.” Many of these puzzles are quite artificial, butyou’ll find yourself thinking much more about bits in working your way through them.LogisticsYou MUST work in a group of at least two people in solving the problems for this assignment. The only“hand-in” will be electronic. Any clarifications and revisions to the assignment will be posted on the courseWeb page. We strongly recommend that you and your partner brainstorm before coding.Handout InstructionsThe materials for the data lab are on the Web at:http://www.cs.hmc.edu/˜geoff/cs105/labs/lab01-data/datalab-handout.tarStart by downloading datalab-handout.tar to a (protected) directory in which you plan to do yourwork. Then give the command: tar xvf datalab-handout.tar. This will cause a number of filesto be unpacked in the directory. The only file you will be modifying and turning in is bits.c.The file btest.c allows you to evaluate the functional correctness of your code. The file README containsadditional documentation about btest. Use the command: make btest to generate the test code andrun it with the command: ./btest. The file dlc is a compiled binary that you can use to check yoursolutions for compliance with the coding rules. (NOTE: dlc is used by the auto grader, so be sure to checkyour solution file prior to submission). The remaining files are used to build btest.Looking at the file bits.c you’ll notice a C structure team into which you should insert the requestedidentifying information about the individuals comprising your programming team. Do this right away soyou don’t forget.The bits.c file also contains a skeleton for each of the 15 programming puzzles. Your assignment is tocomplete each function skeleton using only straightline code (i.e., no loops or conditionals) and a limited1number of C arithmetic and logical operators. Specifically, you are only allowed to use the following eightoperators:! ˜ & ˆ | + << >>A few of the functions further restrict this list. Also, you are not allowed to use any constants longer than 8bits. See the comments in bits.c for detailed rules and a discussion of the desired coding style.EvaluationYour code will be compiled with GCC and run and tested on Wilkes. Your score will be computed out of amaximum of 50 points based on the following distribution:40 Correctness of code running on Wilkes.7.5 Performance of code, based on number of operators used in each function.2.5 Style points, based on your instructor’s subjective evaluation of the quality of your solutions and yourcomments.The 15 puzzles you must solve have been given a difficulty rating between 1 and 4, such that their weightedsum totals to 40. We will evaluate your functions using the test arguments in btest.c. You will get fullcredit for a puzzle if it passes all of the tests performed by btest.c, half credit if it fails one test, and nocredit otherwise.Regarding performance, our main concern at this point in the course is that you can get the rightanswer. However, we want to instill in you a sense of keeping things as short and simple as you can.Furthermore, some of the puzzles can be solved by brute force, but we want you to be more clever. Thus,for each function we’ve established a maximum number of operators that you are allowed to use for eachfunction. This limit is very generous and is designed only to catch egregiously inefficient solutions. Youwill receive .5 points for each function that satisfies the operator limit.Finally, we’ve reserved 2.5 points for a subjective evaluation of the style of your solutions and your com-menting. Your solutions should be as clean and straightforward as possible. Your comments should beinformative, but they need not be extensive.Part I: Bit manipulationsTable 1 describes a set of functions that manipulate and test sets of bits. The “Rating” field gives thedifficulty rating (the number of points) for the puzzle, and the “Max ops” field gives the maximum numberof operators you are allowed to use to implement each function.Function bitNor computes the NOR function. That is, when applied to arguments x and y, it returns˜(x|y). You may only use the operators & and ˜. Function bitXor should duplicate the behavior of thebit operation ˆ, using only the operations & and ˜.2Name Description Rating Max OpsbitNor(x,y) ˜(x|y) using only & and ˜ 1 8bitXor(x,y) ˆ using only & and ˜ 2 14isNotEqual(x,y) x != y? 2 6getByte(x,n) Extract byte n from x 2 6copyLSB(x) Set all bits to LSB of x 2 5logicalShift(x,n) Logical right shift x by n 3 16bitCount(x) Count number of 1’s in x 4 40bang(x) Compute !x without using ! operator 4 12leastBitPos(x) Mark least significant 1 bit 4 6Table 1: Bit-Level Manipulation Functions.Name Description Rating Max Opstmax(void) largest two’s complement integer 1 4isNonNegative(x) x >= 0? 3 6isGreater(x,y) x > y? 3 24divpwr2(x,n) x/(1<<n) 3 15abs(x) absolute value 4 10addOK(x,y) Does x+y overflow? 3 20Table 2: Arithmetic FunctionsFunction isNotEqual compares x to y for inequality. As with all predicate operations, it should return 1if the tested condition holds and 0 otherwise.Function getByte extracts a byte from a word. The bytes within a word are ordered from 0 (least signif-icant) to 3 (most significant). Function copyLSB replicates a copy of the least significant bit in all 32 bitsof the result. Function logicalShift performs logical right shifts. You may assume the shift amount nsatisfies 1 ≤ n ≤ 31.Function bitCount returns a count of the number of 1’s in the argument. Function bang computes logicalnegation without using the ! operator. Function leastBitPos generates a mask consisting of a single bitmarking the position of the least significant one bit in the argument. If the argument equals 0, it returns 0.Part II: Two’s Complement ArithmeticTable 2 describes a set of functions that make use of the two’s complement representation of integers.Function tmax returns the largest integer.Function isNonNegative determines whether x is less than or equal to 0.Function isGreater determines whether x is greater than y.3Function divpwr2 divides its first argument by 2n, where n is the second argument. You may assume that0 ≤ n ≤ 30. It must round toward zero.Function abs is


View Full Document

Harvey Mudd CS 105 - CS 105 Lab 1: Manipulating Bits

Documents in this Course
Processes

Processes

25 pages

Processes

Processes

27 pages

Load more
Download CS 105 Lab 1: Manipulating Bits
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view CS 105 Lab 1: Manipulating Bits and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view CS 105 Lab 1: Manipulating Bits 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?