Download presentation
1
Introduction to Computer Science
Dr. Nagy Ramadan Lecture - 4
2
Outline Part 1 - Binary Addition Part 2 - Binary Subtraction
Part 3 - Subtraction Using the Complement Method Part 4 - Decimal Subtraction using 9’s and 10’s Complement Part 5 - Binary Subtraction using 1’s and 2’s Complement
3
Binary Addition Rules for binary addition are:
= 0 = 1 = 1 = 0 with 1 to carry for the next column = 1 with 1 to carry for the next column Ex 1: Find the sum of the binary numbers 1101 & 110 and verify the result using decimal numbers Solution: (10011)2 = 1*24 + 0*23 + 0*22 + 1*21 + 1*20 = (19)10
4
Ex2: Perform the following binary addition operation then verify the result using decimal numbers: Solution: ( )2 = 1*26 + 1*23 + 1* *2-1 = = (76.5)10
5
Binary Subtraction Rules for binary subtraction are: 0 – 0 = 0
1 – 0 = 1 1 – 1 = 0 0 – 1 = 1 , with 1 borrowed from the next column Ex 1: Use the direct binary subtraction to get the result of: – Verify the result in decimal system. Solution: (10011)2 = 1*24 + 1*21 + 1*20 = (19)10
6
Subtraction Using the Complement Method
The “complement method” allows performing binary subtraction in the form of binary addition which is much easier. This greatly simplifies the design of the electronic circuits of the digital computers. Examples: Decimal Subtraction using 9’s and 10’s Complement Binary Subtraction using 1’s and 2’s Complement
7
Decimal Subtraction using 9’s and 10’s Complement
Ex 1: Decimal subtraction using 9’s complement Solution: The number 6832 is the 9’s complement of 3167
8
The 10’s complement = the 9’s complement + 1
Ex 2: Decimal subtraction using 10’s complement Solution: The 10’s complement = the 9’s complement + 1 The number 6833 is the 9’s complement + 1 of the number Therefore, it is called the 10’s complement.
9
Binary Subtraction using 1’s and 2’s Complement
The 1’s complement of a binary number is simply obtained by replacing every 1 by 0 , and every 0 by 1. The 2’s complement of a binary number can be obtained in two ways: By adding 1 to the 1’s complement. Start the binary number from right. Leave the binary digits unchanged until the first 1 appear, then replace every 1 by 0 , and every 0 by 1.
10
Ex 1: Obtain the two’s complement of the binary number 1011010.110
First solution Second solution
11
Ex 2: Calculate the following binary Subtraction: 11101. 101 – 1011
Ex 2: Calculate the following binary Subtraction: – , then verify the result in decimal System. Solution ( )2 = = ( )10
12
Important Note: When using the complement methods in subtraction and having no additional 1 in the extreme left cell, then , this means a negative result. In this case, the solution is the negative of 1’s complement of the result (if using 1’s complement initially), or the negative of 2’s complement of the result (if using 2’s complement initially).
13
Ex 2: Calculate the following binary Subtraction: 1101. 101 – 11011
then verify the result in decimal System. Solution Therefore, the result = - (the 1’s complement of ) = Or = - ( the 2’s complement of ) =
14
Questions
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.