1 / 33

Cosc 235: Computer Organization

Cosc 235: Computer Organization. Binary Arithmetic. Objectives. Add with binary numbers Represent negative binary numbers in one’s and two’s compliments Perform 3 methods of subtraction with binary numbers Multiply and divide with binary numbers

iliana
Download Presentation

Cosc 235: Computer Organization

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. Cosc 235: Computer Organization Binary Arithmetic

  2. Objectives • Add with binary numbers • Represent negative binary numbers in one’s and two’s compliments • Perform 3 methods of subtraction with binary numbers • Multiply and divide with binary numbers • Subtract decimal numbers by nine’s compliment

  3. Addition Add 2 numbers, A and B, to get the sum, S. A A3A2A1A0 + B +B3B2B1B0 S C S3S2S1S0 Any base: add the digits corresponding to the same power • Carry

  4. Addition • The sum of A0 and B0 produce 2 outputs: • Sum, S, the portion of A0 + B0 that will fit in the 0th position • Carry, C, the portion of A0 + B0 that will not fit in the 0th position and must be considered in the 1st position

  5. Truth Table for Binary Addition A0 B0 C1 S0 0 0 0 0 0 1 0 1 1 0 0 1 1 1 1 0

  6. Non-LSB Addition • If we are not at the LSB of the numbers, we have an additional input: the carry from the previous digit • How many digits do we need to handle a 3-input binary addition?

  7. Truth Table for Binary Addition Ci Ai Bi Ci+1 Si 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

  8. Example: adding 2 binary numbers

  9. Fractional addition 0.01012 = 5/1610 0.01102 = 6/1610 --------- ------- 0.10112 = 11/1610

  10. Storing negative numbers • Sign + magnitude • For base n, we have (n-1)-complement • Representation scheme • Subtract each digit in the negative number from (n-1) • Example: 9’s compliment for base 10 • Example: 1’s complement for base 2 • Binary case: 2’s complement

  11. Nine’s Compliment • The Nine’s Compliment is sometimes used in operations with BCD • 9’s compliment is obtained by subtracting a decimal number from all nines A = 764 A = 23.675 A = 999 A = 99.999 -764-23.675 235 76.324

  12. One’s compliment Pad with leading 0’s for a specific word size • Compliment each bit • Complimenting: change 0 to 1, 1 to 0

  13. Example: obtaining 1’s compliment representation

  14. Binary Subtraction Algorithm • Obtain the 1’s compliment of the subtrahend • Add • Take the MSB carry and add back into the results at the LSB • “End-around carry” • If EAC==0, B>A and result is negative • Compliment result to verify value _ • A - B => A + B + EAC

  15. One’s Compliment Example A 13 1101 -B-10-1010 A 1101 +B +0101 (1)0010 + 1 (EAC) 0011

  16. Example: 1’s compliment subtraction

  17. Fractional One’s Compliment A = 28/32 = .11100 -X = 17/32 = .10001 A .11100 +X+ .01110 (1).01010 + 1 (EAC) .01011 = 11/32

  18. 9’s compliment subtraction

  19. Two’s Compliment • Adding the EAC is cumbersome • Skip this step: use a different storage structure • Two’s Compliment is the One’s compliment + 1

  20. Two’s Compliment: methods for obtaining • A = 2110 = 0101012 A1 = 101010 + 1.. 1010112 = A2 • If X = next power of 2 > A, then set all bits left of and including X. right of X, set bits to X – A • Compliment only bits to the left of the least significant 1

  21. Example: deriving 2’s compliment representation

  22. Subtraction using Two’s Compliment • If the end carry = 1, that indicates a positive result, and the end carry is ignored • If the end carry = 0, that indicates a negative result, and the end carry is ignored • Negative result is in Two’s Compliment form • To verify, take the 2’s compliment of the result

  23. Example: 2’s compliment subtraction

  24. Fractional Two’s Compliment Subtraction 10/1610 = .10102 - 7/1610 = -.01112 .1010 +.1001 (1).0011 = 3/1610

  25. Binary Multiplication • Simpler than decimal multiplication • Only need to shift the multiplicand and add

  26. Example Binary multiplication 00101 multiplicand x 00101 multiplier ------- 00101 multiply by 1 00000 shift and multiply by 0 +00101 shift and multiply by 1 (etc) -------- 0011001 = 24 + 23 + 20 = 25

  27. Another example 011010 multiplicand = 2610 x 001010 multiplier = 1010 -------- 000000 multiply by 0 011010 shift & multiply by 1 000000 shift & multiply by 0 011010 shift & multiply by 1 ---------- 0100000100 28 + 22 = 26010

  28. Binary division • Like multiplication, binary division is easier than decimal division • Our quotient bits can either be a 0 or a 1, not a multiple of the divisor

  29. Division

  30. Binary Division Example

  31. Summary • How the arithmetic operations are performed in binary • Addition • Subtraction • Multiplication • Division

  32. Glossary • One’s Compliment The One’s compliment of a binary number is accomplished by converting all 1’s to 0 and all 0’s to 1 • Two’s Compliment One’s compliment + 1 • Nine’s Compliment Decimal number resulting from the subtraction of a number from all 9’s.

  33. Glossary • End Carry A carry having significance greater than the MSB of either term in an addition • End Around Carry End carry generated during one’s compliment subtraction is taken around and added to the LSB of the sum

More Related