1 / 18

Binary Arithmetic

Binary Arithmetic. Addition in binary. The basic addition table is easy to write down In general, 2 binary nos are added in the usual column-by-column way, carrying a ‘1’ to the next column on the left if necessary Example: 1101 2 + 101 2 = 10010 2

Download Presentation

Binary Arithmetic

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

  2. Addition in binary • The basic addition table is easy to write down • In general, 2 binary nos are added in the usual column-by-column way, carrying a ‘1’ to the next column on the left if necessary • Example: 11012 + 1012 = 100102 • Exercise: Calculate 1011012 + 101112

  3. Addition in binary • The basic addition table is easy to write down • In general, 2 binary nos are added in the usual column-by-column way, carrying a ‘1’ to the next column on the left if necessary • Example: 11012 + 1012 = 100102 • Exercise: Calculate 1011012 + 101112 Answer:10001002

  4. Subtraction in Binary • The method for subtracting decimal nos, column-by-column from right to left, is also used for subtracting binary nos • Example: 110112 – 11012 = 11102 • Exercise: 100102 – 10112

  5. Subtraction in Binary • The method for subtracting decimal nos, column-by-column from right to left, is also used for subtracting binary nos • Example: 110112 – 11012 = 11102 • Exercise: 100102 – 10112 Answer: 1112

  6. Addition in Two’s Complement • Rule for adding integers in two’s complement • Add two bits and propagate the carry • If there is a final carry after the leftmost column addition, discard it • Range in Two’s complement • (2N-1 ) to + (2N-1 -1) • Before performing any arithmetic operation check that the input numbers and the result fall within the range

  7. Summary of Integer representation

  8. Example • (+17) + (+22)  (+39) • 8 bit representation

  9. Example • (+17) + (+22)  (+39) • Solution: Carry 1 00010001 00010110 -------------- 00100111

  10. Example • (+24) + (-17)  (+7) • 8 bit representation Carry 11111 00011000 11101111 ----------------- 00000111 • Discard the last carry

  11. Subtraction in Two’s Complement • There is no difference between addition and subtraction in Two’s complement • To subtract • Take the two’s complement of the second number • Add it to the first number • Number 1 - Number 2 = Number 1 + (-Number 2)

  12. Example • (+101) - (+62)  (+101) + (-62)  (+39) • 8 bit representation Carry 11 01100101 11000010 ---------------- 00100111

  13. Practice Question • Add -35 and 20 by converting to two’s complement • (-35) + (20)  (-15) • 8 bit representation

  14. Solution • Add -35 and 20 • (-35) + (20)  (-15) Carry 111 11011101 00010100 --------------- 11110001

  15. Practice Question • Subtract 20 from 30 by converting to two’s complement • Use 8 bit representation

  16. Practice Question • Subtract 20 from 30 by converting to two’s complement • Also convert the result into decimal • Use 8 bit representation • Solution: 00011110 11101100 --------------- 00001010

  17. Practice Question • Subtract 20 from -30 by converting to two’s complement • Also convert the result into decimal • Use 8 bit representation

  18. Practice Question • Subtract 20 from -30 by converting to two’s complement • Use 8 bit representation • Solution hint: (-30) + (-20) = -50

More Related