Assignment 3 - Bits and Character Encodings

Due: Wednesday, September 25, at 10:00pm

Starter code: a3.tar
Upload solutions via Gradescope as: bits.c

Goals

This assignment is designed to help you with the following:

  • 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

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.c via Gradescope.

Getting the starter package

Unlike the previous two assignments, this one has multiple files to comprise its starter code, including some testing tools. You can access the code package as a downloadable .tar file. As noted in this handy tutorial from Indiana University, you can extract the files and folders contained in a tar file by using the command:

tar xvf whatever.tar

To get started on this assignment:

  1. Login to mantis.mathcs.carleton.edu using VS Code and open your cs208 folder. Go back and look at Lab 0 if you have any questions about how to do this.

  2. In your VS Code terminal, run:

    wget https://cs.carleton.edu/faculty/tamert/courses/cs208-f24/resources/assignments/a3.tar
  3. Still in your VS Code terminal, extract the a3 folder:

    tar xvf a3.tar

This will create a folder named a3 with some stuff in it.

  1. Read the readme.txt file and the function documentation in bits.h and get started.

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, and middle_bits. These don’t require any understanding of UTF-8, and just involve bit operations.

  • To get comfortable 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_utf8 and from_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.