V22.0101 ......Homework Assignment 1 ...... Fall 2012
Binary Representation of Numbers

Assigned: THURS, Sept 13.
First draft Due (by email to etutor): THURS, Sept 27, 11:59pm

Please read the assignment carefully. If you need help, don't hesitate to contact your E-TUTOR, but send the email EARLY, NOT just before the deadline. You can also see the lab tutor or the Professor during their office hours. Even though this is the first assignment, it uses concepts from all of Chapters 2 through 5. However, you do not need to read all of these chapters yet. Read the parts you need, especially Sections 3.3 for the if statement, Section 4.4 for the for loop and pages 37-40 for the Scanner class. We have discussed all of this in class.

Decimal numbers from 0 through 255 can be represented in the binary number system using 8 bits. Here are some examples:

DecimalBinary
0 00000000
1 00000001
2 00000010
3 00000011
7 00000111
15 00001111
16 00010000
25 00011001
128 10000000
129 10000001
254 11111110
255 11111111
Thus, for example, the decimal number 25 is represented in binary as 00011001, meaning 0 times 128 plus 0 times 64 plus 0 times 32 plus 1 times 16 plus 1 times 8 plus 0 times 4 plus 0 times 2 plus 1 times 1. Notice that EACH BIT CORRESPONDS TO A POWER OF 2. Make sure you understand how this works before you go any further.

This assignment asks you to write a Java class called Binary. The decimal number will be stored in the variable num declared in the main method. The class Binary will have two methods that you must write. Here are the details.

Begin by "hard-wiring" the example number into the main method; but when you submit the program, read the number from the the keyboard using the Scanner class described in the text book (page 37-39).

After your program runs properly, alter it slightly so that it can read the data from the command line. If you have a mac, the terminal program gives you the command line. If you have a PC, and are using JCreator see the Arguments Prompt section in the Downloading the Compiler (Version 1.6) and the IDE link. Otherwise, see http://www.computerhope.com/issues/ch000549.htm (the link is on the web page under the assignment) for how to include the java and javac programs in your path. However, the easiest way is to place your program in the Bin directory of the jdk directory. Hand this version into your etutor. To see how the command line works, look at the link How to use the command line part of the assignment for this assignment. If you can't get this version to work, 0.2 points will be deducted from a possible high of 4.0 points.. You should hand in two versions of the assignment. One that uses the Scanner class and one that uses the command line. The command line version should not check whether your input is in range using a do while since you can only input data from the command line when you execute the program.

Please get started on the assignment immediately, and contact the etutor as soon as possible with any questions. Don't expect a response the day before the due date. Late homeworks will be accepted up to 7 days late, but they will be marginally penalized.