You are on page 1of 29

Lecture 2

Dr. Nabil M. Eldakhly


Faculty of Computers and Information –
Department of CS-
CS-SAMS
&
The French University in Egypt (UFE)
Digital Systems &
Binary Numbers (Cont.)
Outline

1. Digital Systems
2. Binary Numbers
3. Number-base Conversions
4. Octal and Hexadecimal Numbers
5. Complements
6. Signed Binary Numbers
7. Binary Codes
8. Binary Storage and Registers
9. Binary Logic
Digital Systems & Binary Numbers (Cont.)
Complements

Complements are used in the digital computers in order to simplify


the subtraction operation and for the logical manipulations.
For each radix-r system (radix r represents base of number system)
there are two types of complements.
̶ Diminished Radix Complement [(r-1)‘s complement]
• Given a number N in base r having n digits, the (r-1)’s
complement of N is defined as
(rn –1) – N
̶ Radix Complement [r's complement]
• Given a number N in base r having n digits, the r’s complement of
N is defined as
rn – N
OR , rn – N = [(rn – 1) – N] + 1
i.e., r’s complement = (r-1)’s complement + 1
4
Digital Systems & Binary Numbers (Cont.)
Complements (Cont.)- Decimal System Complements-
Digital Numbers’ Complements (9’s & 10’s Complements)

Example-1: (r-1)’s complement for N= 546700


• r(base)= 10, n=6, (r-1)’s complement is 9’s complement
• 9’s complement = (rn – 1) – N = (106 – 1) – N = 999999 – N
• 9’s complement of 546700 is 999999 – 546700 = 453299

Example-2: r’s complement for N= 546700


• r(base)= 10, n=6, r’s complement is 10’s complement
• 10’s complement = 9’s complement + 1 = [ (106 – 1) – N]+1 = [999999–N] + 1
• 10’s complement of 546700 is [999999 – 546700]+1
= 453299 +1

5 = 453300 (106-1) = (1000000-1)= 999999


Digital Systems & Binary Numbers (Cont.)
Complements (Cont.)- Decimal System Complements-
Digital Numbers’ Complements (9’s & 10’s Complements)

Example-3: (r-1)’s complement for N= 012398


• r(base)= 10, n=6, (r-1)’s complement is 9’s complement
• 9’s complement = (rn – 1) – N = (106 – 1) – N = 999999 – N
• 9’s complement of 012398 is 999999 – 012398 = 987601

Example-4: r’s complement for N= 012398


• r(base)= 10, n=6, r’s complement is 10’s complement
• 10’s complement = 9’s complement + 1 = [ (106 – 1) – N]+1 = [999999–N] + 1
• 10’s complement of 012398 is [999999 – 012398 ]+1
= 987601 +1

6 = 987602 (106-1) = (1000000-1)= 999999


Digital Systems & Binary Numbers (Cont.)
Complements (Cont.)- Binary System Complements-
Binary Numbers’ Complements (1’s & 2’s Complements)

Example-1: (r-1)’s complement for N= 1011000


• r(base)= 2, n=7, (r-1)’s complement is 1’s complement
• 1’s complement = (rn – 1) – N = (27 – 1) – N = 1111111 – N
o 1’s complement of 1011000 is 1111111 – 1011000 = 0100111
All of 0s become 1s and all of 1s become 0s

Example-2: r’s complement for N= 1011000


• r(base)= 2, n=7, r’s complement is 2’s complement
• 2’s complement = 1’s complement + 1
Take 1’s complement then add 1 to LSB of 1's complement of the number, OR
Toggle all bits to the left of the first ‘1’ from the right
1011000
1’s Complement 0100111
• 2’s complement of 1011000 is + 0000001

7 (27-1) = (128-1)= (127)10 = (1111111)2 0101000


Digital Systems & Binary Numbers (Cont.)
Complements (Cont.)- Binary System Complements-
Binary Numbers’ Complements (1’s & 2’s Complements) (Cont.)

Example-3: (r-1)’s complement for N= 0110111


(r-1)’s complement is 1’s complement
• r(base)= 2, n=7,
(27-1) = (128-1)= (127)10 = (1111111)2
• 1’s complement = (rn – 1) – N = (27 – 1) – N = 1111111 – N
o 1’s complement of 0110111 is 1111111 – 0110111 = 1001000
All of 0s become 1s and All of 1s become 0s

Example-4: r’s complement for N= 0110111


• r(base)= 2, n=7, r’s complement is 2’s complement
• 2’s complement = 1’s complement + 1
Take 1’s complement then add 1 to LSB of 1's complement of the number, OR
Toggle all bits to the left of the first ‘1’ from the right
0110111
1’sComplement 1001000
• 2’s complement of 0110111 is + 0000001

8 1001001
Digital Systems & Binary Numbers (Cont.)
Complements (Cont.)- Arithmetic Subtraction by Complements-
Subtraction by 10’s Complement

I. At first, 10’s complement of the subtrahend is found.


Minuend 72532
II. Then it is added to the minuend. Subtrahend + 3250

III. If there is a final carry over of the sum, it is dropped and the
result is positive.

IV. If there is no carry over, the 10’s complement of the sum will be
the result and it is negative.

9
Digital Systems & Binary Numbers (Cont.)
Complements (Cont.)- Arithmetic Subtraction by Complements-
Subtraction by 10’s Complement- Example-1
Minuend Subtrahend r’s Complement is :
rn – N
Evaluate: 72532 – 3250 = [(rn – 1) – N] + 1
= (r-1)’s Complement + 1
– Solution
At first, • The numbers of digits in the subtrahend is 4 while that of
10’s
complem
minuend is 5. We make the number of digits in the subtrahend
ent of the equal to that of minuend by taking a `0’ in the fifth place of the
subtrahe
nd is subtrahend (i.e., 03250).
found. • Now, 10’s complement of 03250 is ([99999 – 03250] +1), i.e.
Then it is 96750. Adding this with the minuend. 1
added to If there is a final
the
• Minued - 7 2 5 3 2 carry over of the
minuend. • 10’s complement of subtrahend + 9 6 7 5 0 sum, it is
dropped and the
• Result of addition- Carry over 1 6 9 2 8 2 result is positive.

• As there is a carry over, it is dropped and the final result is


positive.
• The required difference is 69282
Digital Systems & Binary Numbers (Cont.)
Complements (Cont.)- Arithmetic Subtraction by Complements-
Subtraction by 10’s Complement- Example-2
Minuend Subtrahend r’s Complement is :
Evaluate: 3250 – 72532 rn – N
= [(rn – 1) – N] + 1
– Solution = (r-1)’s Complement + 1

• The numbers of digits in the minuend is 4 while that of subtrahend is 5.


At first,
10’s We make the number of digits in the minuend equal to that of
comple
ment of subtrahend by taking a `0’ in the fifth place of the minuend (i.e., 03250).
the • Now, 10’s complement of 72532 is ([99999 - 72532] +1) i.e. 27468
subtra
hend is Adding this with the minuend.
If there is no carry over,
found. • Minued - 03250 the 10’s complement of
Then it • 10’s complement of subtrahend +27468 the sum will be the result
and it is negative.
is • Result of addition- No Carry over 30718
added
to the
• As there is no carry over, the result is negative and the final result will
minue be obtained by:
nd. – Calculate the 10’s complement of the result.
– i.e., 10’s complement of 30718 = (9’s Complement of 30718 + 1) =
([99999 - 30718]+ 1)= 69282
11 • Hence, the required difference is – 69282
Digital Systems & Binary Numbers (Cont.)
Complements (Cont.)- Arithmetic Subtraction by Complements-
Subtraction by 2’s Complement

With the help of subtraction by 2’s complement method we can


easily subtract two binary numbers. The operation is carried out by
means of the following steps:

I. At first, 2’s complement of the subtrahend is found.


Minuend 110101
II. Then it is added to the minuend.
Subtrahend +100101
III. If the final carry over of the sum is 1, it is dropped and the result is
positive.

IV. If there is no carry over, the 2’s complement of the sum will be the
result and it is negative.

12
Digital Systems & Binary Numbers (Cont.)
Complements (Cont.)- Arithmetic Subtraction by Complements-
Subtraction by 2’s Complement- Example-1
Minuend Subtrahend If the final carry over of
Evaluate: 110110 – 10110 the sum is 1, it is
dropped and the result
– Solution is positive.

At first, • The numbers of bits in the subtrahend is 5 while that of


2’s minuend is 6. We make the number of bits in the subtrahend
complem
ent of the equal to that of minuend by taking a `0’ in the sixth place of the
subtrahe subtrahend. 2’s Complement = 1’s Complement + 1
nd is
found. • Now, 2’s complement of 010110 is (101001 + 000001) i.e.
101010. Adding this with the minuend.
Then it is • Minued - 1 110110
added to
the • 2’s complement of subtrahend + 101010
minuend • Result of addition- Carry over 1 100000

• As there is a carry over, it is dropped and the final result is


positive.
13 • The required difference is 100000
Digital Systems & Binary Numbers (Cont.)
Complements (Cont.)- Arithmetic Subtraction by Complements-
Subtraction by 2’s Complement- Example-2
If there is no carry over,
Minuend Subtrahend the 2’s complement of
Evaluate: 10110 – 11010 the sum will be the
2’s Complement is : result and it is
negative.
– Solution = 1’s Complement + 1

• 2’s complement of 11010 is (00101 + 00001) i.e. 00110. Adding


At first, this with the minuend.
2’s
complem • Minued - 10110
ent of the
subtrahe
• 2’s complement of subtrahend + 00110
nd is • Result of addition- No Carry over 11100
found.

Then it is
• As there is no carry over, the result is negative and the final
added to result will be obtained by:
the
minuend
– Calculate the 2’s complement of the result.
– i.e., 2’s complement of 11100 = (00011 + 00001) = 00100
• Hence, the required difference is – 00100, i.e., – 100
14
Digital Systems & Binary Numbers (Cont.)
Complements (Cont.)- Arithmetic Subtraction by Complements-
Subtraction by 2’s Complement- Example-3
If the final carry over of the sum
Subtrahend is 1, it is dropped and the result
Minuend
is positive.
Evaluate: 1010.01 – 1001.01
2’s Complement is :
– Solution = 1’s Complement + 1

At first,
• 2’s complement of 1001.01 is (0110.10 + 0000.01) i.e. 0110.11.
2’s Adding this with the minuend. 1
complem
ent of the • Minued - 1010.11
subtrahe • 2’s complement of subtrahend + 0110.11
nd is
found. • Result of addition- Carry over 10001.10

Then it is • As there is a carry over, it is dropped and the final result is


added to
the positive.
minuend • The required difference is 1.10

15
Digital Systems & Binary Numbers (Cont.)
Complements (Cont.)- Arithmetic Subtraction by Complements-
Subtraction by 2’s Complement- Example-4
If there is no carry over, the 2’s
Minuend Subtrahend complement of the sum will be the
result and it is negative.
Evaluate: 10100.01 – 11011.10
2’s Complement is :
– Solution = 1’s Complement + 1

• 2’s complement of 11011.10 is (00100.01 + 00000.01) i.e.


At first,
2’s 00100.10. Adding this with the minuend.
complem • Minued - 1 0 1 0 0. 0 1
ent of the
subtrahe • 2’s complement of subtrahend + 0 1 1 0 0. 1 0
nd is • Result of addition- No Carry over 1 1 0 0 0. 1 1
found.

Then it is • As there is no carry over, the final result is negative and it will
added to be obtained by:
the
minuend – Calculate the 2’s complement of the result.
– i.e., 2’s complement of 11000.11 = (00111.00 + 00000.01) =
00111.01
16 • Hence, the required difference is – 00111.01
Digital Systems & Binary Numbers (Cont.)
Complements (Cont.)- Arithmetic Subtraction by Complements-
Subtraction by 1’s Complement

i. To write down 1’s complement of the subtrahend.


Minuend 110101
ii. To add this with the minuend. Subtrahend -100101

iii. If the result of addition has a carry over then it is dropped and
an 1 is added in the last bit.

iv. If there is no carry over, then 1’s complement of the result of


addition is obtained to get the final result and it is negative.

17
Digital Systems & Binary Numbers (Cont.)
Complements (Cont.)- Arithmetic Subtraction by Complements-
Subtraction by 1’s Complement- Example-1
If the result of addition has a carry over
Minuend Subtrahend then it is dropped and an 1 is added in
the last bit.
Evaluate: 110101 – 100101
– Solution
• 1’s complement of 100101 is 011010.
Write
• Minued - 1 110101
down 1’s
complem • 1’s complement of subtrahend + 011010
ent of the
subtrahe • Result of addition- Carry over 1 001111
nd.
+ 000001
To add
this with
010000
the
minuend
• As there is a carry over, it is dropped and 1 is added in
the last bit.
• The required difference is 10000
18
Digital Systems & Binary Numbers (Cont.)
Complements (Cont.)- Arithmetic Subtraction by Complements-
Subtraction by 1’s Complement- Example-2
If there is no carry over, then 1’s
Minuend Subtrahend complement of the result of addition is
obtained to get the final result and it is
Evaluate: 101011 – 111001 negative.
– Solution
• 1’s complement of 111001 is 000110.
Write
down 1’s • Minued - 101011
complem • 1’s complement of subtrahend + 000110
ent of the
subtrahe • Result of addition- No Carry over 110001
nd.

To add
this with
• As there is no carry over, the final result is negative and
the it will be obtained by:
minuend
– Calculate the 1’s complement of the result.
– i.e., 1’s complement of 110001 is 001110
• Hence, the required difference is – 001110 i.e. – 1110
19
Digital Systems & Binary Numbers (Cont.)
Complements (Cont.)- Arithmetic Subtraction by Complements-
Subtraction by 1’s Complement- Example-3
If there is no carry over, then 1’s
Minuend Subtrahend complement of the result of addition is
obtained to get the final result and it is
Evaluate: 10110.01 – 11010.10 negative.
– Solution
• 1’s complement of 11010.10 is 00101.01.
Write
down 1’s • Minued - 1 0 1 1 0. 0 1
complem • 1’s complement of subtrahend + 0 0 1 0 1. 0 1
ent of the
subtrahe • Result of addition- No Carry over 1 1 0 1 1. 1 0
nd.

To add
this with
• As there is no carry over, the final result is negative and
the it will be obtained by:
minuend
– Calculate the 1’s complement of the result.
– i.e., 1’s complement of 11011.10 is 00100.01
• Hence, the required difference is – 00100.01 i.e. – 100.01
20
Outline

1. Digital Systems
2. Binary Numbers
3. Number-base Conversions
4. Octal and Hexadecimal Numbers
5. Complements
6. Signed Binary Numbers
7. Binary Codes
8. Binary Storage and Registers
9. Binary Logic
Digital Systems & Binary Numbers (Cont.)
Signed Binary Numbers

To represent negative integers, we need a notation for


negative values.
It is customary to represent the sign with a bit placed in the
leftmost position of the number since binary digits.
The convention is to make the sign bit 0 for positive and 1 for
negative.
Example:

22
Digital Systems & Binary Numbers (Cont.)
Signed Binary Numbers-
Arithmetic Addition by Complements-
Addition by 2’s Complement

When negative numbers are expressed in binary addition


using 2’s complement the addition of binary numbers becomes
easier.
This operation is almost similar to that in 1’s complement
system

23
Digital Systems & Binary Numbers (Cont.)
Signed Binary Numbers-
Arithmetic Addition by Complements- Addition by 2’s Complement-
1. Addition of a Positive number & a Negative number- Case I

Case I: When the positive number has a greater magnitude


̶ In this case the carry, which will be generated in the sign bit, is
discarded and the final result is the result of addition.
Example-1: In a 5-bit register find the sum of the following by using 2’s
complement: +1011 and – 0101

Solution:+1011+(–0101)= +1011 – (+0101) (Subtraction by 2’s complement)


1
+1011 010112
- 0101 + 110112  2’s Complement
=
Carry 1 discarded 1001102
1010  1’s Complement
+ 1
---------
1011
̶ Hence the sum is + 0110.
24
Digital Systems & Binary Numbers (Cont.)
Signed Binary Numbers-
Arithmetic Addition by Complements- Addition by 2’s Complement-
1. Addition of a Positive number & a Negative number- Case I (Cont)

Example-2: In a 5-bit register find the sum of the following by using 2’s
complement: + 0111 and – 0011.

Solution: +0111 + (–0011) = +0111 – (+0011) (Subtraction by 2’s complement)

1
+0111 001112
- 0011 + 111012  2’s Complement
=
Carry 1 discarded 1001002 1100  1’s Complement
+ 0001
---------
1101

̶ Hence the sum is + 0100.

25
Digital Systems & Binary Numbers (Cont.)
Signed Binary Numbers-
Arithmetic Addition by Complements- Addition by 2’s Complement-
1. Addition of a Positive number & a Negative number- Case II

Case II: When the negative number has a greater magnitude


̶ In this case, no carry will be generated in the sign bit. The result of
addition will be negative and the final result is obtained by taking 2’s
complement of the magnitude bits of the result.
Example-1: In a 5-bit register find the sum of the following by using 2’s
complement: + 0011 and – 0101
Solution: +0011+(–0101)= +0011 – (+0101) (Subtraction by 2’s complement)
+0011 000112
- 0101 + 110112  2’s Complement
=
No carry over 111102 1010 1’s Complement
+0001
---------
1011
̶ As there is no carry over, the result is negative and the final result will be
obtained by taking 2’s complement of 1110 = (0001 + 0001) = 0010.
26
̶ Hence the required sum is – 0010.
Digital Systems & Binary Numbers (Cont.)
Signed Binary Numbers-
Arithmetic Addition by Complements- Addition by 2’s Complement-
1. Addition of a Positive number & a Negative number- Case II (Cont)

Example-2: In a 5-bit register find the sum of the following by using 2’s
complement: + 0100 and – 0111
Solution: +0100 + (-0111) = +0100 – (+0111) (Subtraction by 2’s complement)

+0100 001002
- 0111 + 110012  2’s Complement
=
No carry over 111012 1000  1’s Complement
+ 0001
---------
1001
̶ As there is no carry over, the result is negative and the final result will be
obtained by taking 2’s complement of 1101= (0010 + 0001) = 0011.
̶ Hence the required sum is – 0011.
27
Digital Systems & Binary Numbers (Cont.)
Signed Binary Numbers-
Arithmetic Addition by Complements- Addition by 2’s Complement-
2. Addition of two Negative numbers

̶ In this case, a carry will be generated from the sign bit which will be
discarded. The negative of 2’s complement of the magnitude bits of the
operation will be the final sum.
Example-1: In a 5-bit register find the sum of the following by using 2’s
complement: – 0011 and – 0101

Solution:
1
- 0011 111012  2’s Complement
- 0101 + 110112  2’s Complement
Carry 1 discarded 1110002

̶ As there is a carry over, the result is negative and the final result will be
obtained by taking 2’s complement of 1000= (0111 + 0001) = 1000.
̶ Hence the required sum is – 1000.
28
Digital Systems & Binary Numbers (Cont.)
Signed Binary Numbers-
Arithmetic Addition by Complements- Addition by 2’s Complement-
2. Addition of two Negative numbers (Cont.)

Example-2: In a 5-bit register find the sum of the following by using 2’s
complement: – 0111 and – 0010.

Solution:
1
- 0111 110012  2’s Complement
- 0010 + 111102  2’s Complement
Carry 1 discarded 1101112

̶ As there is a carry over, the result is negative and the final result will be
obtained by taking 2’s complement of 0111= (1000 + 0001) = 1001.
̶ Hence the required sum is – 1001.

29

You might also like