Presentation is loading. Please wait.

Presentation is loading. Please wait.

CPS120: Introduction to Computer Science Computer Math: Addition and Subtraction.

Similar presentations


Presentation on theme: "CPS120: Introduction to Computer Science Computer Math: Addition and Subtraction."— Presentation transcript:

1 CPS120: Introduction to Computer Science Computer Math: Addition and Subtraction

2 Addition & Subtraction Terms A + B A is the augend B is the addend C – D C is the minuend D is the subtrahend

3 Addition Rules – All Bases Addition Step 1: Add a column of numbers Step 2: Determine if there is a single symbol for the result Step 3: If so, write it and go to the next column. If not, write the accompanying number and carry the appropriate value to the next column

4 Addition of Binary Numbers Rules for adding or subtracting very similar to the ones in decimal system Limited to only two digits 0 + 0 = 0 0 + 1 = 1 1 + 0 = 1 1 + 1 = 0 carry 1

5 Half-Adder Inputs: ABCarrySum 00 0 0 01 0 1 10 0 1 1 1 1 0 The Carry output is a simple AND function, and the Sum is an Excusive-OR. Thus, we can use two gates to add these two bits together. The resulting circuit is shown below.

6 Remember: there are only 2 digits in binary: 0 and 1 Position is key, carry values are used: Carry Values 1 1 1 1 1 1 1 0 1 0 1 1 1 +1 0 0 1 0 1 1 1 0 1 0 0 0 1 0 14 Arithmetic in Binary

7 Full-Adder Inputs: AB C in C out S 0 0 0 0 0 0 0 1 0 1 0 1 0 0 1 0 1 1 1 0 1 0 0 0 1 1 0 1 1 0 1 1 0 1 0 1 1 1 1 1 We can use two half-adder circuits. The first will add A and B to produce a partial Sum, while the second will add C IN to that Sum to produce the final S output. If either half-adder produces a carry, there will be an output carry. Thus, C OUT will be an OR function of the half-adder Carry outputs. The resulting full adder circuit is shown below.

8 Number Overflow Overflow occurs when the value that we compute cannot fit into the number of bits we have allocated for the result. For example, if each value is stored using eight bits, adding 127 to 3 overflow: 01111111 + 00000011 10000010 Overflow is a classic example of the type of problems we encounter by mapping an infinite world onto a finite machine.

9 Subtraction Rules – All Bases Step1: Start with the rightmost column, if the column of the minuend is greater than that of the subtrahend, do the subtraction, if not… Step 2: Borrow one unit from the digit to the left of the once being processed The borrowed unit is equal to “borrowing” the radix Step 4: Decrease the column form which you borrowed by one Step 3: Subtract the subtrahend from the minuend and go to the next column

10 Remember borrowing? Apply that concept here: 1 2 2 0 2 1 0 1 0 1 1 1 - 1 1 1 0 1 1 0 0 1 1 1 0 0 15 Subtracting Binary Numbers

11 Addition & Subtraction of Hex Due to the propensity for errors in binary, it is preferable to carry out arithmetic in hexadecimal and convert back to binary If we need to borrow in hex, we borrow 16 It is convenient to think “in decimal” and then translate the results back to hex


Download ppt "CPS120: Introduction to Computer Science Computer Math: Addition and Subtraction."

Similar presentations


Ads by Google