Unit I (Ids)
Unit I (Ids)
UNIT - I
NUMBER SYSTEM AND BOOLEAN ALGEBRA
NUMBER SYSTEMS AND BINARY CODES
Number systems
Number systems other than the familiar decimal (base 10) number system are used in the
computer field and digital systems. Digital computers internally use the binary (base 2)
number system to represent data and perform arithmetic calculations. The hexadecimal
(base 16) number system is a shorthand method of working with binary numbers. The octal
(base 8) number system is also less commonly used in digital computers.
Example:
1
Example:
1011.01 = 1 x 23 + 0 x 22 + 1 x 21 + 1 x 20 + 0 x 2-1 + 1 x 2-2
= 1 x 8 + 0 x 4 + 1 x 2 + 1 x 1 + 0 x 0.5 + 1 x 0.25
= 11.25 (in decimal)
Octal numbers are used to represent binary numbers. It has eight symbols: 0, 1, 2, 3, 4, 5, 6
and 7. The base (or radix, or weight) of the octal number system is 8. The place value of each
position is given below:
Example:
72.2 = 7 x 81 + 2 x 80 + 2 x 8-1
= 7 x 8 + 2 x 1 + 2 x 0.125
= 58.25 (in decimal)
Hexadecimal numbers are used to represent binary numbers. It has sixteen symbols: 0, 1, 2, 3,
4, 5, 6, 7, 8, 9, A, B, C, E and F. The base (or radix, or weight) of the hexadecimal number
system is 16. Here the decimal number for „A‟ is 10, „B‟ is 11, „C‟ is 12, „D‟ is 13, „E‟ is 14
and „F‟ is 15. The place value of each position is given below:
Example:
3C.A = 3 x 161 + 12 x 160 + 10 x 16-1
= 3 x 16 + 12 x 1 + 10 x 0.0625
= 60.625 (in decimal)
2
Conversion
i) Integer numbers
The “double dabble” method is used to convert decimal number to binary number. In
this method, the decimal number is divided by 2 repeatedly and the remainders are noted after
each division. We have to continue until we get zero in the quotient. The remainders are
taken from bottom to top to get the binary number.
27 † 2 = 13 → Remainder 1
13 † 2 = 6 → Remainder 1
6 † 2 = 3 → Remainder 0
3 † 2 = 1 → Remainder 1
1 † 2 = 0 → Remainder 1
The decimal number is multiplied by 2 repeatedly and the carries integer part (whole
numbers) is noted after each multiplication. We have to continue until we get zero in the
fraction. The process may be stopped after six places. The carries are taken from top to
bottom to get the binary number.
i) Integer numbers
The “octal dabble” method is used to convert decimal number to octal number. In this
method, the decimal number is divided by 8 repeatedly and the remainders are noted after
each division. We have to continue until we get zero in the quotient. The remainders are
taken from bottom to top to get the octal number.
3
Example: To convert the decimal number 175 to octal number
175 † 8 = 21 → Remainder 7
21 † 8 = 2 → Remainder 5
2 † 8 = 0 → Remainder 2
The decimal number is multiplied by 8 repeatedly and the carries (ie.) integer part
(whole numbers) is noted after each multiplication. We have to continue until we get zero in
the fraction. The process may be stopped after three places. The carries are taken from top to
bottom to get the octal number.
i) Integer numbers
The “hex dabble” method is used to convert decimal number to hexadecimal number.
In this method, the decimal number is divided by 16 repeatedly and the remainders are noted
after each division. We have to continue until we get zero in the quotient. The remainders are
taken from bottom to top to get the hexadecimal number.
The decimal number is multiplied by 16 repeatedly and the carries (ie.) integer part
(whole numbers) is noted after each multiplication. We have to continue until we get zero in
the fraction. The process may be stopped after three places. The carries are taken from top to
bottom to get the hexadecimal number.
4
Example: To convert the decimal number 0.23 to hexadecimal number.
0.23 x 16 = 3.68 = 0.68 with carry → 3 → 3
0.68 x 16 = 10.88 = 0.88 with carry → 10 → A
0.88 x 16 = 14.08 = 0.08 with carry → 14 → E
Therefore, 0.2310 = 0.3AE16
Binary Octal
000 0
001 1
010 2
011 3
100 4
101 5
110 6
111 7
5
The following procedure can be used for converting the binary number to octal number:
Step 1 : Group the binary digits in threes, starting at the binary point.
Step 2 : Convert each group of three to its octal equivalent
The binary numbers for the hexadecimal numbers from 0 to F are given in the following
table:
Binary Hexadecimal
0000 0
0001 1
0010 2
0011 3
0100 4
0101 5
0110 6
0111 7
1000 8
1001 9
1010 A
1011 B
1100 C
1101 D
1110 E
1111 F
The following procedure can be used for converting the binary number to octal number:
Step 1 : Group the binary digits in fours, starting at the binary point.
Step 2 : Convert each group of four to its hexadecimal equivalent
6
Octal to decimal conversion
i) Integer numbers
The given octal number can be converted to decimal number by using the following
procedure:
The same procedure used for the integer numbers can be used for fractional numbers also.
The following procedure can be used for converting the octal number to binary number:
7
Octal to hexadecimal conversion
The following procedure can be used for converting the octal number to binary number:
i) Integer numbers
The given hexadecimal number can be converted to decimal number by using the following
procedure:
The same procedure used for the integer numbers can be used for fractional numbers also.
8
Hexadecimal to binary conversion
The following procedure can be used for converting the hexadecimal to binary number:
Step 1 : Write the Hexadecimal number
Step 2 : Write the four digit equivalent binary number
Example: To convert the hexadecimal number 7A.2D to binary number
Step 1 : 7 A . 2 D (Hexadecimal number)
Step 2 : 0111 1010 . 0011 1101 (Binary equivalent)
Binary codes
We use the decimal code to represent numbers. Digital electronic circuits in computers and
calculators use mostly the binary code to represent numbers. Many other special codes are
used in digital electronics to represent numbers, letters, and punctuation marks and control
characters. These special codes are generally called binary codes. Some of the special binary
codes are BCD code, Gray code, and Excess 3 code.
Excess-3 Code
This is another form of BCD code. The code for each decimal digit is obtained by adding
decimal number 3 to the natural BCD code. For example, decimal number 2 is coded as 0010
+ 0011 = 0101 in Excess-3 code. It is a self-complementing code which is very much useful
in performing subtraction operation in digital systems. The Excess-3 codes for the decimal
numbers from 0 to 9 are given in the following table.
9
Decimal Natural BCD Excess-3
number code code
0 0000 0011
1 0001 0100
2 0010 0101
3 0011 0110
4 0100 0111
5 0101 1000
6 0110 1001
7 0111 1010
8 1000 1011
9 1001 1100
Gray Code
It is a special binary code used in optical encoders. In this code, only one bit will change each
time the decimal number is incremented. The BCD codes and Gray codes for the decimal
numbers from 0 to 15 are given in the following table.
Natural BCD
Decimal number Gray code
code
0 0000 0000
1 0001 0001
2 0010 0011
3 0011 0010
4 0100 0110
5 0101 0111
6 0110 0101
7 0111 0100
8 1000 1100
9 1001 1101
10 0001 0000 1111
11 0001 0001 1110
12 0001 0010 1010
13 0001 0011 1011
14 0001 0100 1001
15 0001 0101 1000
Boolean Algebra
In the middle of the 19th century, an English mathematician George Boole developed rules for
manipulations of binary variables, known as Boolean algebra. This is the basis for all digital
systems like computers, calculators, etc. Binary variables can be represented by a letter
symbol such as A, B, X, Y, etc. The variable can have only one of the two possible values at
any time either 0 or 1. The following are the operators used in Boolean algebra.
Operator Operation
= Equal (Assignment)
+ OR (Logic addition)
. AND (Logic multiplication)
(Bar) NOT (Complement)
10
Boolean postulates and laws
Theorems
S.No Theorem
1. 𝐴=A
2. A (𝐴 + B) = A B
3. A+AB=A
4. (A + B) (A + 𝐵) = A
5. AB+𝐴𝐵=A
6. A (A + B) = A
7. A+A𝐵=A+B
8. A + B C = (A + B) (A + C)
S.No Law
1. 0=1
2. 1=0
3. If A = 0, 𝐴 = 1
4. If A = 1, 𝐴 = 0
5. 𝐴=A
AND Laws
S.No Law
1. A.0=0
2. A.1=A
3. A.A=A
4. A .𝐴 = 0
OR Laws
S.No Law
1. A+0=A
2. A+1=1
3. A+A=A
4. A +𝐴 = 1
Commutative Laws
The commutative laws allow the change in position of an AND or OR variable.
S.No Law
1. A+B=B+A
2. A.B=B.A
Associative Laws
The associative laws allow the grouping of variables.
S.No Law
1. A + (B + C) = (A + B) + C
2. A . (B . C) = (A .B) . C
11
Distributive Laws
S.No Law
1. A . (B + C) = (A . B) + (A . C)
2. A + (B . C) = (A + B) . (A + C)
DeMorgan’s theorems
De Morgan contributed a lot for the Boolean algebra. Out of them, the following two
theorems are very important. It allows transformation from a sum-of-products form to a
products-of-sums form. De Morgan‟s theorems are also useful in simplifying Boolean
equations.
First theorem
Statement:
The complement of a sum of variables is equal to the product of their complements.
Equation:
𝐴 + 𝐵 = 𝐴 . 𝐵
Logic diagram :
Proof:
We have to show the left side equals the right side for all possible values of A and B. The
following table proves the De Morgan‟s first theorem.
A B A+B 𝐴 + 𝐵 𝐴.𝐵
(LHS) 𝐴 𝐵 (RHS)
0 0 0 1 1 1 1
0 1 1 0 1 0 0
1 0 1 0 0 1 0
1 1 1 0 0 0 0
In the above table, LHS = RHS. Hence, the De Morgan‟s first theorem is proved.
Second theorem
Statement:
The complement of a product of variables is equal to the sum of their complements.
Equation:
𝐴 . 𝐵 = 𝐴+𝐵
12
Logic diagram :
Proof:
We have to show the left side equals the right side for all possible values of A and B. The
following table proves the De Morgan‟s second theorem.
A B A.B 𝐴 .𝐵 𝐴+
(LHS) 𝐴 𝐵 𝐵(RHS)
0 0 0 1 1 1 1
0 1 0 1 1 0 1
1 0 0 1 0 1 1
1 1 1 0 0 0 0
In the above table, LHS = RHS. Hence, the De Morgan‟s second theorem is proved.
Logic gates
A gate is a logic circuit with one output and one or more inputs. The output signal occurs
only for certain input combinations. The input and output signals are digital in nature ie.
either 0 (low) or 1 (high). All the possible input combinations and their corresponding output
conditions are noted in a table, called truth table.
In digital systems, two different voltage levels (0v and 5v) are used to represent the logic
levels „0‟ and „1‟. If the high voltage level (5v) represents logic „1‟ and low voltage level (0v)
represents logic „0‟, then the system is called positive logic. But some systems use the low
voltage level (0v) for logic „1‟ and the high voltage level (5v) for logic „0‟. This is called
negative logic. This is shown in the following figure.
OR gate
OR gate has two or more inputs and only one output. It works according to the OR boolean
function. It follows the addition (+) law. It gives output when any one of the input is at logic
„1‟. The symbol, logic equation and truth table for OR gate are shown in the following figure.
Inputs Output
A B Y
0 0 0
Y=A+ 0 1 1
B 1 0 1
1 1 1
For a two input OR gate, there are four cases of input combinations, 00, 01, 10 and 11.
13
Case 1 : A = 0 and B = 0
In this case, the output (A + B) = (0 + 0) = 0
Case 2 : A = 0 and B = 1
In this case, the output (A + B) = (0 + 1) = 1
Case 3 : A = 1 and B = 0
In this case, the output (A + B) = (1 + 0) = 1
Case 4 : A = 1 and B = 1
In this case, the output (A + B) = (1 + 1) = 1
For a three input OR gate, there are eight input combinations, 000, 001, 010, 011, 100, 101,
110 and 111. The generalized formula for the number of input combinations is 2n, where „n‟
is the number of inputs in the gate.
AND gate
AND gate has two or more inputs and only one output. It works according to the AND
boolean function. It follows the multiplication (.) law. It gives output only when all the inputs
are at logic „1‟. The symbol, logic equation and truth table for AND gate are shown in the
following figure.
Inputs Output
A B Y
Y=A. 0 0 0
0 1 0
B
1 0 0
1 1 1
For a two input AND gate, there are four cases of input combinations, 00, 01, 10 and 11.
Case 1 : A = 0 and B = 0
In this case, the output (A . B) = (0 . 0) = 0
Case 2 : A = 0 and B = 1
In this case, the output (A . B) = (0 . 1) = 0
Case 3 : A = 1 and B = 0
In this case, the output (A . B) = (1 . 0) = 0
Case 4 : A = 1 and B = 1
In this case, the output (A . B) = (1 . 1) = 1
NOT gate
NOT gate has only one input and only one output. It works according to the complementation
law of boolean algebra. Its output is the complement of the input ie. the output is „1‟ when the
input is „0‟ and the output is „0‟ when the input is „1‟. The symbol, logic equation and truth
table for NOT gate are shown in the following figure.
14
Input Output
Y=A A Y
0 1
1 0
Case 2 : A = 1
In this case, the output (𝐴) = (1) = 0
The other names of NOT gate are Inverter gate and Complement gate.
NOR gate
NOR gate is a combination of OR gate and NOT gate. An OR gate followed by a NOT gate is
a NOR gate. NOR gate has two or more inputs and only one output. It gives output only when
all the inputs are at logic „0‟. The symbol, logic equation and truth table for NOR gate are
shown in the following figure.
Inputs Output
A B Y
Y= 0 0 1
𝐴+ 𝐵 0 1 0
1 0 0
1 1 0
For a two input NOR gate, there are four cases of input combinations, 00, 01, 10 and 11.
Case 1 : A = 0 and B = 0
In this case, the output (𝐴 + 𝐵) = (0 + 0) = 0 = 1
Case 2 : A = 0 and B = 1
In this case, the output (𝐴 + 𝐵) = (0 + 1) = 1 = 0
Case 3 : A = 1 and B = 0
In this case, the output (𝐴 + 𝐵) = (1 + 0) = 1 = 0
Case 4 : A = 1 and B = 1
In this case, the output (𝐴 + 𝐵) = (1 + 1) = 1 = 0
NAND gate
15
NAND gate is a combination of AND gate and NOT gate. An AND gate followed by a NOT
gate is a NAND gate. NAND gate has two or more inputs and only one output. It gives output
only when any one of the input is at logic „0‟. The symbol, logic equation and truth table for
NAND gate are shown in the following figure.
Inputs Output
A B Y
0 0 1
Y = 𝐴 .𝐵 0 1 1
1 0 1
1 1 0
For a two input NAND gate, there are four cases of input combinations, 00, 01, 10 and 11.
Case 1 : A = 0 and B = 0
In this case, the output (𝐴 . 𝐵) = (0 . 0) = 0 = 1
Case 2 : A = 0 and B = 1
In this case, the output (𝐴 . 𝐵) = (0 . 1) = 0 = 1
Case 3 : A = 1 and B = 0
In this case, the output (𝐴 . 𝐵) = (1 . 0) = 0 = 1
Case 4 : A = 1 and B = 1
In this case, the output (𝐴 . 𝐵) = (1 . 1) = 1 = 0
EX-OR gate has two or more inputs and only one output. It gives output only when the inputs
are at different logic levels ie. when one input is „0‟ the other input must be „1‟. This gate can
be constructed using AND, OR and NOT gates. The symbol, logic circuit, logic equation and
truth table for EX-OR gate are shown in the following figure.
Y=𝐴B+A
𝐵
Inputs Output
A B Y
0 0 0
0 1 1
1 0 1
1 1 0
For a two input EX-OR gate, there are four cases of input combinations, 00, 01, 10 and 11.
16
Case 1 : A = 0 and B = 0
In this case, the output (𝐴 . B + A .𝐵) = (1 . 0 + 0 . 1) = (0 + 0) = 0
Case 2 : A = 0 and B = 1
In this case, the output (𝐴 . B + A .𝐵) = (1 . 1) + 0 . 0) = (1 + 0) = 1
Case 3 : A = 1 and B = 0
In this case, the output (𝐴 . B + A .𝐵) = (0 . 0 + 1 . 1) = (0 + 1) = 1
Case 4 : A = 1 and B = 1
In this case, the output (𝐴 . B + A .𝐵) = (0 .1 + 1 . 0) = (0 + 0) = 0
It is a combination of EX-OR gate and NOT gate. An EX-OR gate followed by a NOT gate is
EX-NOR gate. It has two or more inputs and only one output. It gives output only when the
inputs are at same logic levels ie. „00‟ and „11‟. This gate can be constructed using AND, OR
and NOT gates. The symbol, logic circuit, logic equation and truth table for EX-NOR gate
are shown in the following figure.
Inputs Output
A B Y
0 0 1
0 1 0
1 0 0
1 1 1
For a two input EX-NOR gate, there are four cases of input combinations, 00, 01, 10 and 11.
Case 1 : A = 0 and B = 0
In this case, the output (𝐴 . 𝐵 + 𝐴 . 𝐵) =0 . 0 + 0 . 0 = (1 . 0 + 0 . 1) = (0 + 0) = 0 = 1
Case 2 : A = 0 and B = 1
In this case, the output (𝐴 . 𝐵 + 𝐴 . 𝐵) =0 . 1 + 0 . 1 = (1 . 1 + 0 . 0) = (1 + 0) = 1 = 0
Case 3 : A = 1 and B = 0
In this case, the output (𝐴 . 𝐵 + 𝐴 . 𝐵) =1 . 0 + 1 . 0 = (0 . 0 + 1 . 1) = (0 + 1) = 1 = 0
Case 4 : A = 1 and B = 1
In this case, the output (𝐴 . 𝐵 + 𝐴 . 𝐵) =1 . 1 + 1 . 1 = (0 . 1 + 1 . 0) = (0 + 0) = 0 = 1
17
Implementation of logic functions using gates
The following table shows the various logic equations and their equivalent gates.
𝐴 NOT
A+B OR
A.B AND
𝐴+ 𝐵 NOR
𝐴 .𝐵 NAND
𝐴 . B + A .𝐵 EX-OR
𝐴 .𝐵 + 𝐴 . 𝐵 EX-NOR
The given logic function can be realized using gates as per the above table.
Y = (𝐴 . B) + (A .𝐵) + (𝐵 . C) ............................1
Y = (A + B + C) . (𝐴+ 𝐵) ....................................2
The first equation has three terms. Each term is a product term. The logic function is the sum
of the product terms. This function is said to be in Sum-of-products form (or) Min term form.
Similarly, the second equation has two terms. Each term is a sum term. The logic function is
the product for the sum terms. Hence, this function is said to be in Product-of-sums form (or)
Max term form.
18
Implementation of logic functions using gates
Follow the steps given below to draw the logic diagram for the given logic function.
1. For a function in Sum-of-products form, the final output gate is an OR gate. For a
function in Product-of-sums form, the final output gate is an AND gate.
2. Realize the (.) function using AND gate.
3. Realize the (+) function using OR gate.
4. Realize the complement ( ) function using NOT gate.
Example
𝑌 =𝐴+ 𝐵𝐶
𝑌 =𝐴+ 𝐵𝐶
19
Realization of gates using universal gates
We can use only NAND gates for constructing all the other gates (ie. NOT, OR, AND, NOR,
EX-OR and EX-NOR). Similarly, we can useonly NOR gates for constructing all the other
gates. Hence, NAND and NOR gates are called universal gates.
Y=𝐴
= (𝐴 . 𝐴) ……. Because A . A = A
Hence, when we tie the two inputs of an NAND gate together we get a NOT gate.
Y=A+B
= 𝐴+𝐵 ……. Double complementation will give the same function
=𝐴. 𝐵 ….. Using De-Morgan‟s first theorem, 𝐴 + 𝐵 = 𝐴 . 𝐵
Two NAND gates are used for the two NOT functions. A third NAND gate is used for the (.)
and complement functions.
Y=A.B
= 𝐴 .𝐵 ……. Double complementation will give the same function
One NAND gate is used for the 𝐴 . 𝐵 function. Another NAND gate is used for the
complement function.
20
4) NOR gate using only NAND gates
Y=𝐴+ 𝐵
=𝐴.𝐵 ….. Using Using De-Morgan‟s first theorem, 𝐴 + 𝐵 = 𝐴 . 𝐵
=
Two NAND gates are used for the two NOT functions. Another two NAND gates are
required for implementing the (.) ie. AND function. Hence, totally four NAND gates are
required for realizing a NOR gate using only NAND gates.
Y = 𝐴 . B + A .𝐵
Two NAND gates are used for the two NOT functions 𝐴and 𝐵. Another two NAND gates are
required for 𝐴 . 𝐵 and 𝐴 . 𝐵. A final NAND gate is required for the (.) and complement
function. Totally five NAND gates are required for realizing an EX-OR gate using only
NAND gates.
Y = 𝐴.𝐵 +𝐴. 𝐵
When the output of an EX-OR gate is connected to a NOT gate, we get an EX-NOR gate.
Hence, EX-OR gate is realized first using five NAND gates. Sixth NAND gate is used to
realize the NOT gate. Totally six NAND gates are required for realizing an EX-NOR gate
using only NAND gates.
21
Realization of gates using NAND gates only
Y=𝐴
= (𝐴 + 𝐴) ……. Because A + A = A
Hence, when we tie the two inputs of a NOR gate together we get a NOT gate.
Y=A+B
= 𝐴+𝐵 ……. Double complementation will give the same function
When the output of a NOR gate is connected to a NOT gate, we get an OR gate. One NOR
gate is used for 𝐴 + 𝐵. Another NOR gate is used to implement the NOT function.
Y=A.B
= 𝐴 . 𝐵 ……. Double complementation will give the same function
=𝐴+ 𝐵 ……. Using De-Morgan‟s second theorem, 𝐴 . 𝐵 = 𝐴+𝐵
Two NOR gates are used for 𝐴and 𝐵. Another NOR gate is used for (+) and complement
functions.
22
4) NAND gate using only NOR gates
Y=𝐴. 𝐵
=𝐴+𝐵 ….. Using De-Morgan‟s second theorem, 𝐴 . 𝐵 = 𝐴+𝐵
Two NOR gates are used for the two NOT functions. Another two NOR gates are required
for implementing the (+) ie. OR function. Hence, totally four NOR gates are required for
realizing a NAND gate using only NOR gates.
Y = 𝐴 . B + A .𝐵
Two NOR gates are used for the two NOT functions 𝐴and 𝐵. Another two NOR gates are
required for (+) and complement functions. Two more NOR gates are required for the final
(+) operation. Totally six NOR gates are required for realizing an EX-OR gate using only
NOR gates.
Y = 𝐴.𝐵 +𝐴. 𝐵
When the output of an EX-OR gate is connected to a NOT gate, we get an EX-NOR gate.
Hence, EX-OR gate is realized first using five NOR gates. Another NOR gate is used to
realize the NOT gate. The last two NOR gates implemented for the NOT operation can be
removed because double complementation give the same function. Totally five NOR gates
are required for realizing an EX-NOR gate using only NOR gates.
23
Simplification of expression using Boolean techniques
We can simplify logic expressions using Boolean techniques (ie.)Boolean laws and theorems.
Example 1 : Simplify the expression Y = A 𝐵 + A B
Y = A𝐵+AB
= A ( 𝐵 + B) …. By factoring
= A (1) ….. 𝐵 + B = 1
= A ….. A . 1 = A
24
Example :
Find out the Boolean expression for the circuit given below:
25
COMBINATIONAL CIRCUITS
Combinational circuits
26
In digital systems, there are two types of circuits, 1) Combinational logic circuits and 2)
Sequential logic circuits. In combinational circuits, the output depends only on the present
input conditions. But, in sequential circuits, the output depends not only on the present input
conditions but also on the previous output conditions.
Binary Arithmetic
Arithmetic
circuits
Arithmetic circuits are the combinational logic circuits used to perform arithmetic operations
such as addition, subtraction, multiplication and division on binary numbers.
Binary addition
In addition, the first number is called augend and the second number is called is addend. The
result is called the sum. Sometimes, we may get carry also.
Augend
+ Addend
Carry Sum
0 0 1 1
+0 +1 +0 +1
0 1 1 10 Sum = 0 and Carry = 1
1
1
+1
11
Sum = 1 and Carry = 1
In a binary number, the left most bit is called Most Significant Bit (MSB) and the rightmost
bit is called Least Significant Bit (LSB). Addition must be carried out bit by bit starting from
the LSB.
Examples :
1) Add the binary number 101 and 10. (Apply basic rules)
Answer :(111)2
27
Answer :(100110)2
Binary subtraction
In subtraction, the first number is called minuend and the second number is called is
subtrahend. The result is called the difference. Sometimes, we may get borrow also.
Minuend
- Subtrahend
Borrow Difference
0 1 1 0
-0 -0 -1 -1
0 1 0 11 Difference =1, Borrow = 1
Subtraction must be carried out bit by bit starting from the LSB.
When we borrow a 1 from the next bit, we will get 10 (ie. 2 in decimal).
Examples :
1011
-1001
Answer : (10)2 0010
Answer :(11011)2
In decimal systems, we use (+) sign for positive numbers and (–) sign for negative numbers.
But in binary numbers, complement method is used for representing negative numbers. Two
types of complement methods are available.
28
Either 1‟s complement or 2‟s complement method is adopted in a particular digital system.
1’s complement
1‟s complement is used to represent negative numbers. Each bit is subtracted from 1 (borrow
is ignored) to get the 1‟s complement. A shortcut method is also used. Each bit in the given
number is complemented (0 to 1, 1 to 0) to get its 1‟s complement.
Examples :
1) Find the 1‟s complement of 101011.
010100 ---- 0 to 1, 1 to 0
Answer :10100
Answer : 1
2’s complement
2‟s complement is used to represent negative numbers. When we add 1 to 1‟s complement,
we will get the 2‟s complement of the given number.
Examples:
1) Find the 2‟s complement of 101011.
Answer : (010101)2
Answer :(00010)2
The number to be subtracted (subtrahend) is converted into 1‟s complement form or 2‟s
complement form to represent it as a negative number. Then it will be added to the first
number (minuend).
Minuend
+ Complement of
Subtrahend
Difference
29
Binary subtraction using 1’s complement method
The following steps are used to subtract a number using 1‟s complement method
101100
- 100101
Difference
The 1‟s complement of subtrahend 100101 is 011010. This should be added to the minuend.
Minuend 101100
Add 1‟s complement of + 011010
Subtrahend
1 000110 There is a carry 1.
Add Carry + 1
+ 000111 Result is positive.
Answer : + (111)2
Minuend 110110
Add 1‟s complement of Subtrahend + 000001
110111 There is no carry.
Find 1‟s complement
001000
- 001000 Result is negative.
Convert to Decimal - 8
Answer : - 8
30
The following steps are used to subtract a number using 2‟s complement method.
101100
- 100101
Difference
The 2‟s complement of subtrahend 100101 is 011011. This should be added to the minuend.
Minuend 101100
Add 2‟s complement of Subtrahend + 011011
1 000111 There is a carry 1.
Ignore it.
+ 000111 Result is positive.
Answer : + (111)2
Minuend 110110
Add 2‟s complement of Subtrahend + 000010
111000 There is no carry.
Find 2‟s complement 000111
(1‟s complement Plus 1) + 1
- 001000 Result is negative.
Convert to Decimal - 8
Answer : - 8
Sign
31
bit Magnitude bits
For example, an 8-bit signed number 01000100 represents a positive number, because the
sign bit is „0‟. Its magnitude is 1000100. Hence, the equivalent decimal number is +68.
Similarly, the signed number 11000100 represents a negative number, because the sign bit is
„1‟. Its magnitude is 1000100. Hence, the equivalent decimal number is -68.
Half adder
Half adder adds two binary digits at a time. It has two inputs A and B, and two outputs SUM
and CARRY.
𝑆𝑈𝑀 = 𝐴𝐵 + 𝐴𝐵 = A ⊕ B
CARRY = A B
Inputs Outputs
A B CARRY SUM
0 0 0 0
0 1 0 1
1 0 0 1
32
1 1 1 0
When A= 0 and B = 0
0 + 0 ===> Carry = 0, Sum = 0
When A= 0 and B = 1
0 + 1 ===> Carry = 0, Sum = 1
When A= 1 and B = 0
1 + 0 ===> Carry = 0, Sum = 1
When A= 1 and B = 1
1 + 1 ===> Carry = 1, Sum = 0
The logic diagram, truth table and logic equations for SUM and CARRY are given in figure.
From the truth table (A, B and SUM), we find that an EX-OR can be used to produce the
SUM. From the truth table (A, B and CARRY), we find that an AND gate can be used to
produce the CARRY.
Full adder
When we add two bits, we may get a carry bit. Hence, an adder circuit needs to add three bits
(ie. two input bits A and B and one carry bit C). The logic circuit which adds three bits is
called Full adder. The truth table of full adder is given in table.
Inputs Outputs
A B C CARRY SUM
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
A full adder can be implemented using two half adders and an OR gate as shown in the
figure.
33
Figure : Block diagram of full adder using two half adders
The logic diagram and logic equations for SUM and CARRY are given in figure.
SUM = A ⊕ B ⊕ C
CARRY = A B + (A ⊕ B) C
The first Half adder HA1 is used to add A and B. Its SUM output and C are added by the
second Half adder HA2. The SUM output of HA2 is the final SUM. The carry outputs of
HA1 and HA2 are ORed to get the final CARRY output.
Half subtractor
Half subtractor subtracts one binary bit from another binary bit at a time. It has two inputs A
and B, and two outputs DIFFERENCE and BORROW.
When A= 0 and B = 0
0 - 0 ===> Borrow = 0, Difference = 0
When A= 0 and B = 1
0 - 1 ===> Borrow = 1, Difference = 1
When A= 1 and B = 0
1 - 0 ===> Borrow = 0, Difference = 1
When A= 1 and B = 1
1 - 1 ===> Borrow = 0, Difference = 0
34
The logic diagram, truth table and logic equations for DIFFERENCE and BORROW are
given in figure.
Borrow = 𝐴 . B
Inputs Outputs
A B BORROW DIFFERENCE
0 0 0 0
0 1 1 1
1 0 0 1
1 1 0 0
DIFFERENCE = 𝐴𝐵 + 𝐴𝐵 = A ⊕ B
BORROW = 𝐴 B
From the truth table (A, B and DIFFERENCE), we find that an EX-OR gate can be used to
produce the DIFFERENCE. From the truth table (A, B and BORROW), we find that A‟.B
will give the BORROW. Hence, a NOT gate and an AND gate are used to produce the
BORROW.
Full subtractor
When we subtract two bits, we may get a borrow bit. Hence, a subtractor circuit needs to
subtract three bits (ie. two input bits A and B and one borrow bit C). The logic circuit which
subtracts three bits is called Full subtractor. The truth table of full subtractor is given in table.
Inputs Outputs
A B C BORROW DIFFERENCE
0 0 0 0 0
0 0 1 1 1
0 1 0 1 1
0 1 1 1 0
1 0 0 0 1
1 0 1 0 0
1 1 0 0 0
1 1 1 1 1
35
A full subtractor can be implemented using two half subtractors and an OR gate as shown in
the figure.
Borrow
The logic diagram and logic equations for DIFFERENCE and BORROW are given in figure.
DIFFERENCE = A ⊕ B ⊕ C
BORROW = 𝐴 B + (𝐴 ⊕ 𝐵) C
The first Halfsubtractor HS1 is used for (A - B). Then C is subtracted from (A-B) using the
second Half subtractor HS 2. The DIFFERENCE output of HA2 is the final DIFFERENCE.
The BORROW outputs of HS1 and HS2 are ORed to get the final BORROW output.
36