
Binary Representation of Numbers

Assigned: WED, Jan 24.
First Version Due (by email to etutor): (Marateck) TUES, Feb 6, at midnight

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 TA 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.1 and 3.3.2 for the if statement and Section 4.4 for the for loop.


0 00000000
1 00000001
2 00000010
3 00000011
7 00000111
15 00001111
16 00010000
25 00011001
128 10000000
129 10000001
254 11111110
255 11111111

This assignment asks you to write a Java class called Binary. The decimal number will be stored in the variable numVal. Another variable binStr will store the binary string corresponding to numVal. The class Binary will have two methods that you must write. Here are the details.

You can "hard-wire" the example numbers into the main method, or you can read them from the the keyboard using the Scanner class described in the text book (page 53). You must have JDK1.5 or later, and import java.util.Scanner to use the Scanner class. To read an integer you would write Scanner kbd = new Scanner(System.in); followed by int num = kbd.nextInt().


