This lab is scheduled for 23 & 24, January.
Normally, we wouldn't start with this lab, but since the lecture won't meet until next week, we'll start with a review of binary arithmetic by returning to a Java applet used in an old lab from CSCI from CSCI 201. Then we'll revive some more CSCI 201 memories by modifying a Java program to compute some binary functions.
To make it all more interesting you'll do this while learning a bit about the Linux operating system.
Finally, if you have some time, you might want to review the home page for CSCI 255.
We are not going to have detailed descriptions of the Linux login procedure in this handout. Your lab instructor will demonstrate that for you.
If you are a Linux guru, go help someone who is not a Linux guru.
By the way, because we don't have enough Linux computers for every one in the class to have his/her own, some of you with either (1) have to share or (2) use a Solaris computers.
Under the direction of the lab instructor, log onto the Linux workstation and start up two terminal windows. Use the userid and password distributed in class.
If you have "lost" the userid and password, the lab instructor can reset your account.
Note to lab instructor: Use the command sudo /usr/local/etc/resetuser USERID on woodfin to reset lost accounts.
Start up the netscape browser by typing the command:
Now load this page and continue working the lab from its on-line version . The URI is:
If you do not intend to read email on the UNCA CSCI computers, use the program pico to create a file called .forward in your home directory. This file should contain your real email address and nothing else. pico is the text editing part of pine, the mail program you briefly used in Lab 2 of CSCI 107.
Return to the Unix shell (command processor) and use the following Unix commands to create a read-protected subdirectory called csci/255/lab1. The first command, mkdir, creates the directory. The second command, chmod, protects your subdirectory csci, so that normally only you can access its contents. For more information on Unix file protection review Paula Edmiston's CSCI 107 tutorial on The UNIX Operating System.
Although the above chmod would normally remove read, write, and execute (rwx) permission for group members and others (go) for your directory csci; on the UNCA CSCI workstations there are special programs that allow all UNCA faculty to access student files stored within the csci directory.
Connect to your lab directory. Next use the Unix cp command to copy several files to your directory. Be sure to note the single period at the end of this command line. The period is the way Unix and DOS represent the current directory.
Now use the pwd and ls, with the -l option, commands to verify your directory creation and file transfer. You should see something like the following:
skyland% pwd /woodfin/facusers/brock/csci/255/lab1 skyland% ls -l total 2 -rw-r--r-- 1 brock man 1345 Jan 22 18:59 Truth.java
It is not necessary for the lab instructor to view the output of these commands. The existence of your csci/255/lab1 directory and the above file will be checked with Unix shell scripts.
Log out of the Linux workstation and give your teammate an opportunity to perform the lab up to this point.
In CSCI 201, you demonstrated your knowledge representation by mashing some buttons to match a binary number to a decimal numbers. We want repeat the game rules here. If you've forgotten them, go back and reread the first part of Lab 3 of CSCI 201.
First try some 8-bit numbers.
Target | Your guess |
---|---|
21 | |
22 | |
44 | |
-1 |
Now try out binary representations using 16 bits.
Target | Your guess |
---|---|
255 | |
1024 | |
2002 | |
-1 |
If you have questions, ask the instructor. Otherwise, we're going to assume you really did do this part of the lab.
Go back to your terminal window, the one with the shell. Remember that your lab directory contains a single file called Truth.java. Use the JDK, Java Development Kit, to compile this Java source file into a Java class file.
If the compile fails, you should get the attention of your instructor. The most likely reason for a problem would be an incorrect PATH environment variable.
Note to lab instructor: The PATH variable should contain either /usr/local/bin or /usr/local/jdk1.3.1_02/bin.
Now run the compiled program with the following command:
You should see the following output.
NAND F F F WRONG! F T F WRONG! T F F WRONG! T T F Implies F F F WRONG! F T F WRONG! T F F T T F WRONG!
If you look at the first few lines of
your Java program, you'll
see that it contains two functions Func1
and Func2
. Both functions are called with
two boolean values and return a boolean value.
The first function, Func1
, is supposed to
compute the NAND (not-AND) function, one of the stars of
digital logic. The NAND function can be described by
the following truth table.
Inputs | Output | |
---|---|---|
false | false | true |
false | true | true |
true | false | true |
true | true | false |
The second function, Func2
, is supposed to
compute the implies function, one of the stars of
symbolic logic. This function can be described by
the following truth table.
Inputs | Output | |
---|---|---|
false | false | true |
false | true | true |
true | false | false |
true | true | true |
However, as you see, our two functions are wrong 75% of the time. Your task is to modify the two functions so that they always return the correct values.
In completing this assignment, you will cycle through the following sequence of Unix commands until your program works correctly.
When you are done, you may log out of the Linux workstation and go home. However, you are encouraged to have your lab instructor verify your work before you depart.