2 Code Logic Gate 26.8.22

Download as pdf or txt
Download as pdf or txt
You are on page 1of 23

CODES AND LOGIC

GATE
• In general we understand or use digital data, but computer system
understand binary.
• So the digital data is represented and stored as group of bits called binary
codes.
CODES • Code is a symbolic representation of discrete information, which may be
present in the form of numbers, letters or physical quantities.
• The symbols used are the binary digits 0 and 1 which are arranged
according to the rules of codes.
• Codes are broadly classified into five groups:
(i) Weighted Binary Codes
(ii) Non-weighted Codes
• Weights are attached to each binary digits. Bits are multiple by
the weights indicates; the sum of these weighted bits given the
equivalent decimal digits.
WEIGHTED • BCD code : represented using 4 bits and follows 8421
BINARY CODES sequence or weights are attached t each binary digits as per
8421 sequence.
5----0101
Decimal number 8421(BCD code) 5421

0 0000 0000

1 0001 0001

2 0010 0010
SOME WEIGHTED 4-BIT
3 0011 0011
BINARY CODES
4 0100 0100

5 0101 1000
69
0110 1001 6 0110 1001
10
1010 7 0111 1010
00010
8 1000 1011
15.45
0001 0101. 0100 0101 9 1001 1100
• Non-weighted codes are codes that are not
positionally weighted.

NON- • This means that each position within a binary number


WEIGHTED is not assigned a fixed value.
CODES • Examples of non-weighted codes:
Excess-3 codes
Gray codes
Decimal number 8421(BCD CODE) Excess 3 code
0 0000 0011
1 0001 0100
2 0010 0101
3 0011 0110
4 0100 0111
EXCESS-3 CODES: 5 0101 1000
OBTAIN BY ADDING 3 TO A DECIMAL NO.
6 0110 1001
7 0111 1010
8 1000 1011
9 1001 1100
• Excess 3 code of 643
• = add 3 to every digit 10
+3
• 976 13
1101

• 12 10 9
1 0
• 1100 1010 1001 3 3

• 1001 0111 0110 4 3


0100 0011
GRAY CODE

• The gray code belongs to a class of Decimal Binary code Gray


codes called minimum change code. number code
0 0000 0000
• In which only one bit in the code
1 0001 0001
group changes when moving from 2 0010 0011
one step to the next. 3 0011 0010
• In gray code two adjacent code 4 0100 0110

number, differ by only one bit. So it 5 0101 0111

is called unit-distance code. 6 0110 0101


7 0111 0100
5
B--0101
G—0111
• A binary number can be converted to its Gray code
B---10110 when:
G---11101
(i) The first bit (MSB) of the Gray code is the same as the first bit
of the binary number;
CONVERSION OF (ii) The second bit of the Gray code equals the exclusive-OR, of
A BINARY the first and second bits of the binary number, i.e. it will be 1 if
NUMBER TO these binary code bits are different and 0 if they are the same;
GRAY CODE (iii) The third Gray code bit equals the exclusive-OR of the
second and third bits of the binary number. And so no
G--0111

B---0101
• Conversion of a Gray code into its binary form involves the
G---1011
reverse of the previous procedure:
B-- 1101
(i) The first binary bit (MSB) is the same as that of the first Gray
code bit.
CONVERSION (ii) If the second Gray bit is 0, the second binary bit is the same
FROM GRAY as that of the first binary; if the second Gray bit is 1, the second
CODE TO BINARY binary bit is the inverse of its first binary bit.
(iii) Step 2 is repeated for each successive bit.
1011----1101
EXAMPLES

• Binary to gray
• A. 10110 B. 10101101

• Gray to binary
• 110101
• 1010111
LOGIC GATES

OR Gate

If A and B are the input variables of an OR gate and Y is its output, then
Y = A+B
Input A INPUT B OUTPUT Y
0 0 0
0 1 1
1 0 1
1 1 1
LOGIC GATES

• AND Gate

If A and B are the input variables of an AND gate and Y is its output, then
Y = A⋅B

Input A INPUT B OUTPUT Y


0 0 0
0 1 0
1 0 0
1 1 1
LOGIC GATES

• NOT Gate (Inverter)

A NOT gate using a transistor is shown in Fig. in which A represents the


input and Y represents the output, i.e. = A’

Input A OUTPUT Y
0 1
1 0
DEMORGAN’S THEOREMS

• The first theorem states that the complement of a product is equal to the sum of the complements. That
is, if the variables are A and B, then

• The second theorem states that, the complement of a sum is equal to the product of the complements.
In equation form, this can be written as
LOGIC GATES

• NAND Gate

NAND is a contraction of the NOT–AND gates. It has two or more inputs and only one output, i.e. Y = (A .B)’

Input A INPUT B OUTPU


TY
0 0 1
0 1 1
1 0 1
1 1 0
LOGIC GATES

• NOR Gate

NOR is a contraction of NOT–OR gates. It has two or more inputs and only one output, i.e. Y = (A+B)’

Input A INPUT B OUTPUT Y


0 0 1
0 1 0
1 0 0
1 1 0
UNIVERSAL GATES / UNIVERSAL BUILDING BLOCKS
• NAND and NOR gates are
called Universal gates or
universal building blocks
because both can be used to
implement any gate like
AND,OR and NOT gates or any
combination of these basic
gates.
UNIVERSAL GATES / UNIVERSAL BUILDING BLOCKS
EXCLUSIVE-OR (EX-OR) GATE
An Exclusive-OR gate is a gate with two
or more inputs and one output. The
output of a two-input Ex-OR gate
assumes a HIGH state if one and only
one input assumes a HIGH state. This is
equivalent to saying that the output is
HIGH if either input A or input B is
HIGH exclusively, and low when both
are 1 or 0 simultaneously.
Input A INPUT B OUTPUT Y
0 0 0
0 1 1
1 0 1
1 1 0
EX OR GATE

EX-OR GATE USING NOR GATE


EXCLUSIVE-NOR (EX-NOR) GATE

• The exclusive-NOR gate, is an Ex-OR gate, followed by an inverter. An exclusive-NOR gate has two
or more inputs and one output. The output of a two-input Ex-NOR gate assumes a HIGH state if both
the inputs assume the same logic state or have an even number of 1s, and its output is LOW when the
inputs assume different logic states or have an odd number of 1s
Input A INPUT B OUTPUT Y
0 0 1
0 1 0
1 0 0
1 1 1

You might also like