1278 represents the number 1*103 + 2*102 + 7*101 +8*100
In octal system (base = 8, digits : 0,1,2,3,4,5,6,7) the number 1274 represent the value 1*83+2*82+7*81+4*80= ...
Digital computers use two digits to count (0 and 1). When we reach "2" we carry a 1 to the next column. Numbers greater than 1 can be represented by using a notation that makes use of the powers of 2. For example:
10010 represents the number 1*24 + 0*23 + 0*22 + 1*21 +0*20These are the first 16 binary numbers:
This is equivalent to 24 +21 which equals 16 + 2, which equals 18.
| Decimal | Binary |
| 0 | 0000 |
| 1 | 0001 |
| 2 | 0010 |
| 3 | 0011 |
| 4 | 0100 |
| 5 | 0101 |
| 6 | 0110 |
| 7 | 0111 |
| 8 | 1000 |
| 9 | 1001 |
| 10 | 1010 |
| 11 | 1011 |
| 12 | 1100 |
| 13 | 1101 |
| 14 | 1110 |
| 15 | 1111 |
Addition in binary is performed using the following principles: 0 + 0 = 0, 0 + 1 = 1, 1 + 0 = 1, and 1+ 1 = 10 (where we carry the 1).
For example:
Confirm this by translating these numbers into decimal!
1001 +0111 10000
Binary addition consists of three input and two output values. The input values
are the carry in (which is 0 for the right most column), and the two digits for
the column currently being added. The output values are the carry out and the
sum. The carry out from one column is the carry in for the column to its left.
The addition above can by expressed as follows:
| carry in | A's digit | B's digit | carry out | sum | |
| Step1 | 0 | 1 | 1 | 1 | 0 |
| Step 2 | 1 | 0 | 1 | 1 | 0 |
| Step 3 | 1 | 0 | 1 | 1 | 0 |
| Step 4 | 1 | 1 | 0 | 1 | 0 |
| Step 5 | 1 | 1 | 1 | 1 | 1 |
| Carry In | A | B | Carryout | Carry In | A | B | Sum | |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |
| 0 | 0 | 1 | 0 | 0 | 0 | 1 | 1 | |
| 0 | 1 | 0 | 0 | 0 | 1 | 0 | 1 | |
| 0 | 1 | 1 | 1 | 0 | 1 | 1 | 0 | |
| 1 | 0 | 0 | 0 | 1 | 0 | 0 | 1 | |
| 1 | 0 | 1 | 1 | 1 | 0 | 1 | 0 | |
| 1 | 1 | 0 | 1 | 1 | 1 | 0 | 0 | |
| 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
Write Boolean expressions for the CarryOut and the Sum.
CarryOut = (! CarryIn && A && B ) ||
(CarryIn && !A && B ) ||
(CarryIn && A && !B ) ||
(CarryIn && A && B)
Step 2: Your text shows you how to write Boolean expressions in Java. By way of review: the "!" operator negates a Boolean value, the "&&" operator "ands" two Boolean values and the "| |" operator "ors" two values. Express your solutions to step 1 as Java. Examine the program FullAdder.java and fill in the missing pieces. Look for the comments that say "FIX THIS." You can copy the code from ~mmmartin/www/CMSC220Labs/Labs/Lab4/AdderCode. Note that there is a function XOR defined in Adder that you might find useful.
You will need to write a worker class that tests all eight cases given in the table above. For example, use the KeyIn method readBoolean() to request Boolean values (look up readBoolean in the index of your book). You will also need to write an application class to start up your worker class. If you get stuck in the logic, you may use the Adder.class method in the AdderCode structure for the next step.
Step 3: A cascading adder is one that hooks the carry out from one column to the carry in of another. Examine the class AdderCode/Arithmetic.java and try running the ArithApp class. The Arithmetic.java file contains comments that say "QUESTION". Answer them directly in the code, then save the file under the name "Answers.java".
Step 4: Make a copy of the original Arithmetic.java code and then modify
the code as specified in the comment at the top labeled "MODIFY INSTRUCTIONS".
If you keep the Arithmetic.java name for this file, then you can re-use the
ArithApp class for testing.
In this lab you are required to produce a lab report and to arrange for a demo of your solutions. Do NOT!!! include code in your lab report.
The code you write should include:
ASK!!!!!!! questions, in class, in lab, during office hours and especially via the class newsgroup. Please do not phone.
GET HELP FROM ANY ONE AND EVERYONE. If there is something that is not clear to you ASK!!!!