CS 105

Lab Setup

You should have already worked through the startup steps for accessing the CS 105 server. If not, do it now!

Starter Code

The starter code for this lab is already available on the server in the directory `/cs/cs105/labs/lab1-bits'. The first step is to make your own copy of the code to work on. From your working directory, run the following commands:

mkdir -p ~/cs105
cd ~/cs105
cp -ai /cs/cs105/labs/lab1-bits .
cd lab1-bits

You can paste them all in at once. Once you've done that, you're ready to start working on the lab! (Don't run this command again later; it will overwrite your work!)

Look at the README File

There's a README file in the lab directory that contains an overview of the files present and has a quick summary of what you need to do in the assignment (although you're likely better off reading the instructions here on the course website)

You can read it using the less command:

less README

bits.c

The only file you will be modifying and turning in is bits.c.

Add your names and your knuth login ids in the comments at the top of bits.c!

For practice, open the file in emacs by typing

emacs bits.c

add your names, look around a bit, and then save and exit by typing C-x C-s to save and C-x C-c to exit. (Remember, C- means hold the Control key while pressing the next key; more details are in the help page on emacs.)

The bits.c file contains a skeleton for each of the 14 programming puzzles. Your assignment will be to complete each function skeleton using only straight-line code for the integer puzzles (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.

Also, you are not allowed to use any constants longer than 8 bits. All constants must fall in the decimal range \( [0,255] \). See the comments in bits.c for detailed rules and a discussion of the desired coding style.

We'll cover the functions you need to write in the next sections of the lab instructions, so you don't need to dive in right now.

For now, just run:

make

and if everything is set up correctly, it'll build the program btest, and then you can run that with:

./btest

to see the results of running the tests on the functions as they are now. You'll see that right now, all the tests fail because none of the functions have been implemented yet.

You can also test your code doesn't break any of the rules by using the dlc tool. As provided, it should pass without any errors. You can run it with:

./dlc bits.c

(if everything is okay, it won't print anything).

To Complete This Part of the Assignment

You'll know you're done with this part of the assignment when you've done all of the following:

(When logged in, completion status appears here.)