You are on page 1of 13

SABA INSTITUTE OF HIGHER EDUCATION

FACULTY OF COMPUTER SCIENCE

Computer Fundamentals

Khalil Ahmad Faizi


Content

• Binary addition
• Binary Subtraction
• Signed magnitude
• 1`s complements
• 2`s complements

9/30/2023 Khalil Ahmad Faizi 2


Binary Addition

In binary • Ex
0+0=0 00001100+00001101= 00011001
1+0=1 12 + 13 = 25
0+1=1
1+1=0 with 1 carry

9/30/2023 Khalil Ahmad Faizi 3


Binary Subtraction

In binary • Ex
0-0=0 00001101-00001100 = 00000001
1-0=1 13 - 12 = 1
0-1=1 one barrow
1-1=0

9/30/2023 Khalil Ahmad Faizi 4


Signed Magnitude
• Uses the Most Significant Bit (MSB) as the sign bit.
• In signed magnitude
• 0 represent positive number
• 1 represent negative number
• Each binary number should be a clear bit length
Ex: bit length 8bits
1. 12 = 00001100
2. -12 = 10001100

9/30/2023 Khalil Ahmad Faizi 5


Complements
• Complements are used to represent negative numbers in digital
systems.
• The following two methods are used to find complements:
1. 1`s complement
2. 2`s complement

9/30/2023 Khalil Ahmad Faizi 6


1`s Complements
The following steps are performed to represent the negative numbers in
1`s complement form.
• Determine the number of bits to represent the number
• Convert the number into binary
• Place 0s to the left of binary number until we have the require number
of bits.
• Then placing all 1s with 0s and all 0s with 1s

Number Binary 1`s complement


-12 00001100 11110011

9/30/2023 Khalil Ahmad Faizi 7


2`s Complements
The following steps are performed to represent the negative numbers in 2`s
complement form.
• Determine the number of bits to represent the number
• Convert the number into binary
• Place 0s to the left of binary number until we have the require number of
bits.
• Then placing all 1s with 0s and all 0s with 1s
• Last step is add 1 with changed number

Number Binary 1`s complement 2`s complement


-12 00001100 11110011 11110100

9/30/2023 Khalil Ahmad Faizi 8


Examples
Subtraction using 1`s complement
Ex: calculate 38-29 using 8-bits 1`s complement
Solution :
• Step 1 : convert both numbers into binary form using 8-bits
38 + (-29)
38 = 00100110 29 = 00011101
• Step 2 : find 1`s complement of negative number
-29 = 11100010
• Step 3 : add the result of step 2 to the other number of the question
00100110 + 11100010 = 100001000
there will occur one carry bit , discard this carry from number.
9/30/2023 after excluding the last carry bit , the
Khalil result
Ahmad Faiziis 00001000 9
Continue…
• Step 4 : add last carry bit to the result of step 3
00001000 + 1 = 00001001
the result in binary form is 00001001
• Step 5 : convert binary number into decimal
00001001 = 9

9/30/2023 Khalil Ahmad Faizi 10


Examples
Subtraction using 2`s complement
Ex: calculate 45-63 using 8-bits 1`s complement
Solution :
• Step 1 : convert both numbers into binary form using 8-bits
45 + (-63)
45 = 00101101 63 = 00111111
• Step 2 : find 2`s complement of negative number
-63 = 11000001
• Step 3 : add the result of step 2 to the other number of the question
00101101 + 11000001 = 11101110
9/30/2023 note: there is no last carry bit Khalil Ahmad Faizi 11
Continue…
• Step 4 : find 2`s complement of the result of step 3 and place a negative
sign before it
- 00010010
• Step 5 : convert binary number into decimal
- 00010010 = -18

9/30/2023 Khalil Ahmad Faizi 12


Any question?

9/30/2023 Khalil Ahmad Faizi 13

You might also like