CS 242 Fall 2010 : Assignment 1.2 | charlie on software

CS 242 Fall 2010 : Assignment 1.2

This page last changed on Sep 01, 2010 by cemeyer2.

Implementing a bit manipulation library

Suggested Reading
Chapter 5: Working Classes from Code Complete 2.

For this assignment, you will start with your code from last week and:

  • Implement the BitLibrary class
  • Ensure that all of your unit tests from last week pass
Due Date
This assignment must be submitted to Subversion by 8am on Thursday, September 9th in a folder called Assignment1.2


  • learn how to implement to a specification
  • learn how to create a solid and usable library


You will work with the code that you completed for Assignment 1.1. The library must be able to read in a stream of bits, one bit at a time, from some data source. Similarly, it must be able to write a stream of bits, one bit at a time. We give you the outline for the functions that you need to implement. Feel free to add any helper functions to your library, but at minimum you must implement what is given. If you have ideas on how to change the given spec to be better or different, post your ideas on the newsgroup for discussion/approval.

The specific functions are:

  • readBit
  • readByte
  • readShort
  • readInt
  • readLong
  • readNBits
  • writeBit
  • writeByte
  • writeShort
  • writeInt
  • writeLong
  • writeNBits (you might need to change this in your code)
  • flush
Flushing the write buffer
The flush function forces any buffered data that is waiting to be written immediately to disk. It is up to you to decide whether the write functions write into an internal buffer or immediately to disk.
In the given code, the return values on some of the functions are there only so that the code will compile. The intention is that the return values from the read functions will return the read value, not some status indicator.

Library Properties

The library should exhibit two following crucial properties.

1) Reversibility

Any write operations that save a sequence data to disk, must reproduce the exact same sequence of data when it is read from disk.

2) Compactness

The library must write data as dense as possible. There must be no wasted space (bits) between data (bits). For example, if you perform eight writeBit operations, the output should take up exactly one byte on the disk. Two writeBit operations followed by a writeByte operation should take up no more than two bytes on disk. (For this assignment we can assume that data on disk is stored at byte-level granularity). Additionally, the library should never lose any information when storing to disk – the last bits of data are never clipped off because they don’t exactly fill up an entire byte.

Internally, it doesn’t matter what data structures are used to represent the stream of bits. However, once they are filed out to the disk, they must be real bits! To see what’s actually written to disk:

Under NO circumstances should the characters ‘0’ and ‘1’ written out to a file instead of the actual bits 0 and 1. This means you should not be able to open a file in a text editor and read “01010101101”.

If you happen to be outputting the characters ‘A’, ‘0’ and ‘1’, the output bits should be:

Value Binary Hex Decimal
‘A’ ‘0’ ‘1’ 01000001 00110000 00110001 41 30 31 65 48 49

Getting Started

You can work off of the same Eclipse project as you did for Assignment 1.1, but since we are asking you to commit it to a different folder in SVN, you will have to do the following:

  1. right click on your Assignment1 project
  2. select team -> disconnect
  3. select the radio button to “Also delete SVN meta-information from the file system”
  4. click Yes
  5. right click on the project again, select team -> share project
  6. follow the same steps as you did to share Assignment 1.1 (also listed on Using Subversion From Eclipse)

Your task

Again, for this week you are to:

  • Implement the BitLibrary class
  • Ensure that all of your unit tests from last week pass


You must submit your code to SVN by 8am on Thursday, September 9th. Please submit your code to a folder called Assignment1.2.


We will use the standard Grading rubric for this assignment.

Criteria Weight Comment
Code submission 1 Same as before.
Basic preparation 1 Same as before.
Requirements satisfaction 4 Your implementation of the library is fully implemented and all unit-tests pass.
Presentation 2 Same as before.
Participation 2 Same as in before.
Testing 2 A second look at your tests.
Documentation 2 Focusing on the documentation for your implementation
Naming 2 Same as in before.
Decomposition 2 Your methods short and understandable.
Personal issue 2 You satisfactorily handled any issues from 1.1
Effort 2 Refer to Grading.
Cleverness 1 Refer to Grading.
Performance 1 Refer to Grading.
Document generated by Confluence on Feb 22, 2012 18:13

  1. No comments yet.

  1. No trackbacks yet.