1 / 11

Binary Addition and Subtraction | Introduction to Computer Science

Learn about addition and subtraction in computer math, including binary numbers and hex calculations. Understand the rules and carry values for accurate computations.

sharonjames
Download Presentation

Binary Addition and Subtraction | Introduction to Computer Science

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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. Inputs: A B Carry Sum 0 0 0 0 0 1 0 1 1 0 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. Half-Adder

  6. Arithmetic in Binary 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

  7. Inputs: A B Cin Cout 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 CIN to that Sum to produce the final S output. If either half-adder produces a carry, there will be an output carry. Thus, COUT will be an OR function of the half-adder Carry outputs. The resulting full adder circuit is shown below. Full-Adder

  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. Subtracting Binary Numbers 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

  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

More Related