CS 4, Summer 2006: HW 4, due Friday, August 4

Instructions

The first part of this homework involves writing JavaScript, along with some HTML to hold it. Follow the same instructions as in HW 1 -- write code by hand, make it easy to read, print it from the text editor, timestamp it, and upload it to your private folder. For both problems, you are being provided with some code. Edit and and extend it, and then turn in the whole thing (not just your part). Indicate where you have modified the provided code.

The second part of this homework is a set of written questions. You are not required to write your answers in HTML. However, you should still upload them to your private directory and provide a printout. Upload your file in a format we can read -- plain text, HTML, PDF, Word, or RTF. No timestamp is required.

JavaScript Problems [50 points]

  1. [25 points]
    This problem considers how to use packets to deliver a message. The message must be split at the sender, may be corrupted during transmission, and must be reassembled at the receiver. Provided in hw4-packets.html is the basic structure of a program to do the splitting and reassembly.
    packets snapshot

    There are three levels: the original message, the individual packets, and the reassembled message. At the top level is a text box in which the original message is entered, and a text box in which the packet size is entered. Pressing a button then "packetizes" the message (splits it into packets of the size), for display in the second level. Pressing another button "reassembles" whatever is in the textarea for display in the third level. Note that the packetized message may be modified (e.g., removing, reordering, or duplicating packets) before reassembly.

    Some hints:

    For extra credit (only do this once the whole rest of the homework is in great shape, and only if you want to), provide additional functionality, such as a checksum for error detection.

  2. [25 points]
    We saw that bits can be used to represent anything and everything. Here we use a bit representations for a simple drawing program. Provided in hw4-pixels.html is the basic structure.
    pixels snapshot

    Extend the code to provide save and open functionality. Rather than dealing with a file, just "save" to a text box or textarea and get back from it. The exact format of how you do that is up to you, but I would recommend basing it on a string of 0s and 1s (using charAt to get each one). The functions should complement each other -- when you save something, do some more pixel manipulation, and then load, you should be right back where you were.

    For extra credit (only do this once the whole rest of the homework is in great shape, and only if you want to), provide additional functionality, such as colors rather than just black-and-white, the ability to draw lines or text, etc.

    Some hints:

Written Problems [50 points]

  1. [10 points]
    Is it true that the Ethernet protocol guarantees that a message will be delivered? Argue your case in a sentence or two.
  2. [10 points]
    Pick a handful of your favorite cities, and draw a diagram that has connections between some pairs of cities (but not all). (As you saw with my drawing in class, geographic fidelity is not required.) For each connection, indicate the distance (you can just estimate it). Now, pick a pair of cities that aren't directly connected, and list some of the possible routes between them. What's the shortest? What would happen if a message made it partway along that route and then one of the upcoming connections was broken?
  3. [15 points]
    Write your first name in binary. (If you have a long first name, you may choose to write only the first 5 letters.) To do this, first determine the (decimal) ASCII code for each letter, and then convert the ASCII character code to binary. You can look up the answers for the binary representations, but use this as an opportunity to practice the conversion process. Indicate why each binary representation is correct, by writing the individual powers of 2 that are added to yield the decimal value.
  4. [5 points]
    Perform binary addition on the binary representation of the first two letters of your name. Show the carry bits.
  5. [10 points]
    Choose two floating point numbers, one positive and one negative, each with at least 2 digits after the decimal point. Show the internal representation of these numbers, using the representation from class, with 10 bits for mantissa (including sign) and 6 bits for exponent (including sign).