- Learn about binary addition and subtration
- Learn a bit about binary fractions
- Modify and run a Java program

As usual

`mkdir csci/274/lab07``chmod go-rx csci/274/lab07``cd csci/274/lab07``cp /usr/local/csci/274/lab07/* .`

In order to compile Java, you must be logged into either a Sun Sparc or a Digital Alpha workstation. If you are not logged into one of these machines type the following commands:

`xhost +tuxedo``rlogin tuxedo``cd csci/274/lab07``setenv DISPLAY`*your-machine*`:0`

where *your-machine* is the name of the computer you are now logged
into. You should now see two java source files in your directory,
`AddEm.java` and `FloatEm.java`.

The Java applet running below adds two binary numbers. The squares in the applet are the two numbers being added. Right now, all of the squares should be black. However, press the mouse button on one of the squares and notice that it changes from black to red. A black square represents the binary value 0, and a red square represents the binary value 1.

The top row of circles represents the carry being propagated through the addition. The bottom row represents the output sum. Play with the applet for a minute. Add 17 (10001) to 63 (111111) and see if you get 80 (1010000). Then replace the 17 with -17 and look for 46 (101110) as the result.

The Java source for the binary add applet

I suspect you've guessed your assignment by now. Yep, you are to modify
the file `AddEm.java` so that it subtracts rather than adds. There
really isn't that much you need to do: (1), you need to change the initial
carry, `m_Carry[0]`, and (2) you need to change the
`recomputeOutputs` method. If you are really eager you can make
other enhancements, such as adding an overflow indicator or printing 0's and
1's in the squares and circles.

You'll need to use `pico` to modify `AddEm.java`,
`javac` to recompile the program, and `appletviewer` to
view the result. The sequence of commands for doing this will be:

`pico AddEm.java``javac AddEm.java``appletviewer AddEm.html`

Good luck.

The row of squares in the following applet represent a binary fraction. Press on some of the squares and notice that the printed fraction and the sliding bar changes to represent the real number between 0 and 1 corresponding to the fractional bits.

The java source for the binary fraction applet

Your assignment for this applet is pretty simple. Set the bits so that
they represent a binary fraction very close to .1997. As soon as you have
done this, email the fraction to `brock@cs.unca.edu`.

Return to CSCI 274 labs

Return to CSCI 274 home page

Return to Dean Brock's home
page

Return to the UNCA Computer Science home
page