Intro to C #1: select-column
Starter code: bits-package.tar
Upload solutions via Moodle as: bits.tar
This is an individual assignment, so you should write and submit your own code. See the course information page for guidance on how and when it's OK to discuss homework with your classmates.
This assignment is an adaptation of an assignment developed for the Carnegie Mellon University’s 15-213 (Introduction to Computer Systems) course. We'll do several of these Carnegie Mellon assignments this term. They are great, but they come with a lot of infrastructure, which may take you a little while to get used to. We’ll talk about this in class.
Goals
- Practice using C's bitwise operators and boolean operators
- learn some of the fundamentals of C programming
- start thinking of your data in terms of bits and bytes
- work with bitwise operators (~, |, &, ^, <<, >>) in C
Rubric
Your task is to implement the seven functions whose detailed
descriptions you will find in bits.c. Each of the functions is known as
a "puzzle" in much of this assignment's documentation.
For each function/puzzle in this assignment, your score will depend on the function computing the right result with only the specified C operators ("correctness") and doing so with no more than the specified number of operators ("operation count"). Each puzzle's correctness score is shown in the function's comment under the heading "Rating" (1, 2, or 3 points). Each puzzle's operation count score is 1 point, regardless of the Rating.
What to do
- As described in the JupyterHub lab, get yourself a terminal on mantis.
After
cd-ing to whatever working directory you want to use on mantis, download and expandbits-package.tarlike so:wget https://cs.carleton.edu/faculty/jondich/courses/cs208_f25/assignments/packages/bits-package.tar tar xvf bits-package.tarTest your installation of
bits-package:cd bits-package ./driver.plThe Perl program
driver.plis a Carnegie Mellon creation that compiles yourbits.c, tests each function's correctness and operation count, and prints out your total score in tabular form.If you get a "Permission denied" error when you try to run
./driver.pl, you might have to change the permissions like so:chmod +x driver.pl- Read the
READMEfile for details on how each of your implementations should be constructed. - Read all the comments in
bits.ccarefully. - Implement as many of the functions/puzzles as you can. You can
test your implementations any time with
./driver.pl. - To submit your work, upload your
bits.c(and onlybits.c) on Moodle.
A little advice
- Pay careful attention to
README. There are coding rules there that will be enforced bydriver.pl. - You are welcome, of course, to look at any of the files in
bits-packageto try to figure out how CMU's infrastructure works. But you only need to pay attention toREADMEandbits.cto complete the assignment. There are some handy identities to remember with bitwise operators:
x & (~x) gives all 0s x | (~x) gives all 1s x & x gives x x | x gives x x ^ (~x) gives all 1s x ^ x gives all 0s- Getting used to thinking about sequences of bits takes a bit (ha!) of time, and even once you're acclimated to bit-land, some of these puzzles are just tricky. So start early enough to enable you to go for a walk, go get dinner, or get a good night's sleep if you get stuck.
- As noted in
README, you should not#include <stdio.h>inbits.c. This is just a weird quirk of the CMU correctness-checking process. (They should have fixed this, but they didn't, and neither did we.)
Have fun!
Don't by shy about experimenting and asking lots of questions.