Electronic handin will be available after 5PM on Thursday.
A byte is an 8-bit binary (base 2) value. Bytes can store integer values or codes representing characters or other types of data. When a byte stores an unsigned (positive) integer, each bit position represents a power of 2 as shown below.
------------------------------- | | | | | | | | | _______________________________ 7 6 5 4 3 2 1 0 2 2 2 2 2 2 2 2
If the bit in any position is 1, then the corresponding power of 2 is added to its total value. For example, the byte 10101001
------------------------------- | 1 | 0 | 1 | 0 | 1 | 0 | 0 | 1 | _______________________________ 7 6 5 4 3 2 1 0 2 2 2 2 2 2 2 2
is equal to 27 + 25 + 23 + 20 = 128 + 32 + 8 + 1 = 169.
1. Find the dates of the following three events:
2. Write a simple Java program in a project named Program0 that contains one class named DateDisplayer that displays a date in binary using three bytes. For the year, use only the last two decimal digits (e.g. 41 instead of 1941, 3 instead of 2003, etc.). As an example, if the date to be displayed is 12/7/1941, the three required bytes are
00001100 00000111 00101001
YOUR PROGRAM DOES NOT NEED TO COMPUTE THE THREE BYTES ITSELF. IT ONLY NEEDS TO PRINT OUT THE BYTES. SO YOU SHOULD COMPUTE THE NECESSARY BYTES FIRST BY HAND AND THEN WRITE YOUR PROGRAM TO PRINT OUT THE THREE BYTES.
Program Requirements:
Your DateDisplayer class must have three methods as described below.
1. Write a static method named display1 that prints out a single 1 without moving the cursor to the next line.
2. Write a static method named display0 that prints out a single 0 without moving the cursor to the next line.
3. Write a main method that prints out the three bytes for the three dates above by calling the display1 and display0 methods as many times as you need in the proper sequence to get the correct bytes for each date. Include slashes between month, day and year for readability. Then print out each date in its regular format (in decimal).
Here is a sample output for one sample date:
In binary, Pearl Harbor Day is 00001100/00000111/00101001. This date is 12/7/41.
Compile and test that your program runs correctly. If your program does not compile and run, you will not receive full credit for your assignment.
See the course website for instructions on how to hand in your program. Remember that the work you submit must be your own. Also, late hand-ins are not accepted. Please plan ahead and submit early to avoid server overload at the deadline. The deadline is based on the server's clock, not your clock. Please do not email your code to your instructor or course assistant as your official hand-in; these will not be graded.