Assignment 2 - Bits and Character Encodings
Due: Wednesday, April 9, at 10:00pm
Starter code: a2.tar
Upload solutions via Gradescope as: bits.c
Goals
This assignment is designed to help you with the following:
- further working with bit operations (
~,|,&,^,<<,>>) in C - diging into the details of the UTF-8 character encoding
- practicing writing your own tests
Collaboration policy
For this assignment, you may work alone or with a partner, but you must type up all of the code yourself. (It is therefore unexpected for two code submissions to be completely identical.)
You may also discuss the assignment at a high level with other students.
You should list any student with whom you discussed the assignment, and the manner of discussion (high level, partner, etc.) in comments at the top of your C source file(s).
If you work alone, you should say so instead.
Assessment
To demonstrate proficiency, your submission needs to:
- pass the happy-path autograder tests (these have names starting with
"_P") - follow the requirements for each function (especially using only bitwise operations where specified)
- be somewhat well-styled
To demonstrate mastery, your submission needs to:
- demonstrate proficiency
- pass all autograder tests
- be quite well-styled, particularly with well-chosen variable names, naming all magic numbers, good identation, and using helper methods/loops to reduce code duplication
- have thorough error-handling
- include your name and collaboration statement at the top of your C source file(s)
Your assignment
This assignment is based on the same original codebase as Assignment 1, but without all of the machinery around it.
In this assignment, your job is to implement the five functions described in bits.h; all of your coding will be done in bits.c.
The only file you are required to submit is bits.c. We will use our own main.c and Makefile to do our testing and grading.
Keep the following in mind as you do your work:
- You should only write code in
bits.c(the starter version is provided for you). - Do not change
bits.h. - You will submit your
bits.cvia Gradescope.
Getting the starter package
Like the previous assignment, this one has multiple files to comprise its starter code, including some testing tools. Like before, you can access the code package as a downloadable .tar file.
To get started on this assignment:
-
Login to
mantis.mathcs.carleton.eduusing VS Code and open yourcs208folder. Go back and look at Lab 0 if you have any questions about how to do this. -
In your VS Code terminal, run:
wget https://cs.carleton.edu/faculty/tamert/courses/cs208-s25/resources/assignments/a2.tar -
Still in your VS Code terminal, extract the
a2folder:tar xvf a2.tar
This will create a folder named
a2with some stuff in it.
- Read the
readme.txtfile and the function documentation inbits.hand get started.
Testing your code
There are some simple tests provided for you in main.c. These test our first three functions. You can modify this file as you see appropriate to add more tests.
As explained in the readme.txt file, you can take advantage of the Makefile to run these tests:
-
use
maketo just build thebitsexecutable with the code inmain.c -
use
make testto run all tests defined in theMakefile– you can add tests here following these examples to test to_utf8 and from_utf8
Submitting your work
To submit this assignment, you should upload your bits.c to Gradescope.
Advice
-
Read the function definitions in
bits.h. They are there to help you! -
Start with
to_lower,to_upper, andmiddle_bits. These don’t require any understanding of UTF-8, and just involve bit operations. -
To get more practice with bit operations in your program, write out examples on paper or use CTutor with “byte-level view of data” selected (from the dropdown that starts with “none default view” showing).
-
For UTF-8, try out Jeff’s UTF-8 encoder to check different values.
-
For
to_utf8andfrom_utf8, start by getting single-byte codepoints to work, then two-byte codepoints, etc. Worry about cleaning up your duplicated code after you have everything working.