4781_unit II-digital Logic Fundamendals
4781_unit II-digital Logic Fundamendals
4781_unit II-digital Logic Fundamendals
Binary Codes – 8421, 2421, Excess-3, Reflected Code – Error Detection Codes – Alphanumeric Code
– Basic.
Logic Gates.
1
Different Types of Binary Codes | BCD (8421), 2421, Excess-3, Gray
BCD Code:
BCD code is an abbreviation for Binary coded Decimal codes.
It is a numeric weighted code, in which each digit of a decimal number is represented by a separate
group of 4-bits.
There are several BCD codes like 8421, 2421, 3321, 4221, 5211, 5311, 5421, etc.
The most common and widely used BCD code is 8421 code.
In 8421 code, the weights associated with 4 bits are 8, 4, 2, 1 from MSB to LSB.
That is, the weight associated with 3rd bit is 8, the weight associated with 2nd bit is 4, the weight
associated with 1st bit is 2 and the weight associated with 0th bit is 1.
The following table shows the 8421 code for 0-9 decimal numbers.
2
EXCESS-3 CODE:
3
THE GRAY CODE:
The MSB in the Gray code is the same as corresponding MSB in the binary number.
Going from left to right, add each adjacent pair ofbinary code bits to get the next Gray
code bit. Discard carries.
GRAY-TO-BINARY CONVERSION
The MSB in the binary code is the same as thecorresponding bit in the Gray
code.
Add each binary code bit generated to the Gray code bit inthe next adjacent position.
Discard carries.
Ex: Convert the Gray code word 11011 to binary
1 1 0 1 1
+ + + +
1 0 0 1 0
4
APPLICATION OF GRAY CODE:
The main applications include being used in analog to digital converters, as well as being used
for error correction in digital communication.
Gray code is used to minimize errors in converting analog signals to digital signals.
5
2421 CODE:
This code also a 4 bit application code where the binary weights carry 2, 4, 2, 1 from left to right.
DECIMAL 2421
BINARY NUMBER
NUMBER CODE
0 0 0000
1 1 0001
2 10 0010
3 11 0011
4 100 0100
5 101 1011
6 110 1100
7 111 1101
8 1000 1110
9 1001 1111
6
ERROR DETECTION CODE:
The error detection codes are the code used for detecting the error in the received data bit
stream.
In these codes, some bits are included appended to the original bit stream.
Error detecting codes encode the message before sending it over the noisy channels.
The encoding scheme is performed in such a way that the decoder at the receiving can find the
errors easily in the receiving data with a higher chance of success.
1. PARITY CODE:
It is easy to include append one parity bit either to the left of MSB or to the right of LSB of
original bit stream.
There are two types of parity codes, namely
even parity code and
odd parity code based on the type of parity being chosen.
The value of even parity bit should be zero, if even number of ones present in the
binary code. Otherwise, it should be one.
So that, even number of ones present in even parity code.
Even parity code contains the data bits and even parity bit.
The following table shows the even parity codes corresponding to each 3-bit
binary code.
Here, the even parity bit is included to the right of LSB of binary code.
7
Binary Code Even Parity bit Even Parity Code
000 0 0000
001 1 0011
010 1 0101
011 0 0110
100 1 1001
101 0 1010
110 0 1100
111 1 1111
Here, the number of bits present in the even parity codes is 4. So, the possible even number of ones in
these even parity codes are 0, 2 & 4.
If the other system receives one of these even parity codes, then there is no error in the received
data. The bits other than even parity bit are same as that of binary code.
If the other system receives other than even parity codes, then there will be an errors in the
received data. In this case, we can’t predict the original binary code because we don’t know the
bit positions of error.
Therefore, even parity bit is useful only for detection of error in the received parity code. But, it is not
sufficient to correct the error.
The value of odd parity bit should be zero, if odd number of ones present in the binary code.
Otherwise, it should be one. So that, odd number of ones present in odd parity code. Odd parity
code contains the data bits and odd parity bit.
The following table shows the odd parity codes corresponding to each 3-bit binary code. Here,
the odd parity bit is included to the right of LSB of binary code.
8
Binary Code Odd Parity bit Odd Parity Code
000 1 0001
001 0 0010
010 0 0100
011 1 0111
100 0 1000
101 1 1011
110 1 1101
111 0 1110
Here, the number of bits present in the odd parity codes is 4. So, the possible odd number of ones in
these odd parity codes is 1 & 3.
If the other system receives one of these odd parity codes, then there is no error in the received
data. The bits other than odd parity bit are same as that of binary code.
If the other system receives other than odd parity codes, then there is an errors in the received
data. In this case, we can’t predict the original binary code because we don’t know the bit
positions of error.
Therefore, odd parity bit is useful only for detection of error in the received parity code. But, it is not
sufficient to correct the error.
9
ASCII CODE
The ASCII stands for American Standard Code for Information Interchange.
The ASCII code is an alphanumeric code used for data communication in digital computers.
The ASCII is a 7-bit code capable of representing 27 or 128 number of different characters.
The ASCII code is made up of a three-bit group, which is followed by a four-bit code.
10
1. CONTROL CHARACTERS
The non-printable characters used for sending commands to the PC or printer are known as
control characters.
We can set tabs, and line breaks functionality by this code.
The control characters are based on telex technology. Nowadays, it's not so much popular in use.
The character from 0 to 31 and 127 comes under control characters.
2. SPECIAL CHARACTERS
All printable characters that are neither numbers nor letters come under the special characters.
These characters contain technical, punctuation, and mathematical characters with space also.
The character from 32 to 47, 58 to 64, 91 to 96, and 123 to 126 comes under this category.
3. NUMBERS CHARACTERS
This category of ASCII code contains Ten Arabic numerals from 0 to 9.
4. LETTERS CHARACTERS
In this category, two groups of letters are contained, i.e., the group of uppercase letters and the
group of lowercase letters.
The range from 65 to 90 and 97 to 122 comes under this category.
11
ASCII Table
The values are typically represented in ASCII code tables in Decimal, Binary, And Hexadecimal
Form.
Hexa ASCII
Binary Decimal Description Group
decimal Symbol
The null character encourage the device to Control
0000000 0 0 NUL
do nothing Character
The symbol SOH(Starts of heading) Control
0000001 1 1 SOH
Initiates the header. Character
The symbol STX(Start of Text) ends the
Control
0000010 2 2 STX header and marks the beginning of a
Character
message.
The symbol ETX(End of Text) indicates the Control
0000011 3 3 ETX
end of the message. Character
The EOT(end of text) symbol marks the Control
0000100 4 4 EOT
end of a completes transmission Character
The ENQ(Enquiry) symbol is a request that Control
0000101 5 5 ENQ
requires a response Character
The ACK(Acknowledge) symbol is a Control
0000110 6 6 ACK
positive answer to the request. Character
Control
0000111 7 7 BEL The BEL(Bell) symbol triggers a beep.
Character
Lets the cursor move back one step Control
0001000 8 8 BS
(Backspace) Character
A horizontal tab that moves the cursor
TAB Control
0001001 9 9 within a row to the next predefined position
(HT) Character
(Horizontal Tab)
Causes the cursor to jump to the next line Control
0001010 A 10 LF
(Line Feed) Character
The vertical tab lets the cursor jump to a Control
0001011 B 11 VT
predefined line (Vertical Tab) Character
Control
0001100 C 12 FF Requests a page break (Form Feed)
Character
Moves the cursor back to the first position Control
0001101 D 13 CR
of the line (Carriage Return) Character
Switches to a special presentation (Shift Control
0001110 E 14 SO
Out) Character
Switches the display back to the normal Control
0001111 F 15 SI
state (Shift In) Character
Changes the meaning of the following Control
0010000 10 16 DLE
characters (Data Link Escape) Character
0010001 Control characters assigned depending Control
11 17 DC1
on the device used (Device Control) Character
0010010 Control characters assigned depending Control
12 18 DC2
on the device used (Device Control) Character
12
Hexa ASCII
Binary Decimal Description Group
decimal Symbol
Control characters assigned depending Control
0010011 13 19 DC3
on the device used (Device Control) Character
Control characters assigned depending Control
0010100 14 20 DC4
on the device used (Device Control) Character
The negative response to a request Control
0010101 15 21 NAK
(Negative Acknowledge) Character
Synchronizes a data transfer, even if no
Control
0010110 16 22 SYN signals are transmitted (Synchronous
Character
Idle)
Marks the end of a transmission block Control
0010111 17 23 ETB
(End of Transmission Block) Character
Makes it clear that transmission was
Control
0011000 18 24 CAN faulty and the data must be discarded
Character
(Cancel)
Indicates the end of the storage medium Control
0011001 19 25 EM
(End of Medium) Character
Replacement for a faulty sign Control
0011010 1A 26 SUB
(Substitute) Character
Initiates an escape sequence and thus
Control
0011011 1B 27 ESC gives the following characters a special
Character
meaning (Escape)
Control
0011100 1C 28 FS File separator.
Character
Control
0011101 1D 29 GS Group separator.
Character
Control
0011110 1E 30 RS Record separator.
Character
Control
0011111 1F 31 US Unit separator.
Character
Special
0100000 20 32 SP Blank space
Character
Special
0100001 21 33 ! Exclamation mark
Character
Special
0100010 22 34 “ Only quotes above
Character
Special
0100011 23 35 # Pound sign
Character
Special
0100100 24 36 $ Dollar sign
Character
Special
0100101 25 37 % Percentage sign
Character
Special
0100110 26 38 & Commercial and
Character
Special
0100111 27 39 ‘ Apostrophe
Character
13
Hexadec ASCII
Binary Decimal Description Group
imal Symbol
Special
0101000 28 40 ( Left bracket
Character
Special
0101001 29 41 ) Right bracket
Character
Special
0101010 2A 42 * Asterisk
Character
Special
0101011 2B 43 + Plus symbol
Character
Special
0101100 2C 44 , Comma
Character
Special
0101101 2D 45 - Dash
Character
Special
0101110 2E 46 . Full stop
Character
Special
0101111 2F 47 / Forward slash
Character
0110000 30 48 0 Numbers
0110001 31 49 1 Numbers
0110010 32 50 2 Numbers
0110011 33 51 3 Numbers
0110100 34 52 4 Numbers
0110101 35 53 5 Numbers
0110110 36 54 6 Numbers
0110111 37 55 7 Numbers
0111000 38 56 8 Numbers
0111001 39 57 9 Numbers
Special
0111010 3A 58 : Colon
characters
Special
0111011 3B 59 ; Semicolon
characters
Special
0111100 3C 60 < Small than bracket
characters
Special
0111101 3D 61 = Equals sign
characters
Special
0111110 3E 62 > Bigger than symbol
characters
Special
0111111 3F 63 ? Question mark
characters
Special
1000000 40 64 @ At symbol
characters
Capital
1000001 41 65 A
letters
14
Hexadec ASCII
Binary Decimal Description Group
imal Symbol
Capital
1000010 42 66 B
letters
Capital
1000011 43 67 C
letters
Capital
1000100 44 68 D
letters
Capital
1000101 45 69 E
letters
Capital
1000110 46 70 F
letters
Capital
1000111 47 71 G
letters
Capital
1001000 48 72 H
letters
Capital
1001001 49 73 I
letters
Capital
1001010 4A 74 J
letters
Capital
1001011 4B 75 K
letters
Capital
1001100 4C 76 L
letters
Capital
1001101 4D 77 M
letters
Capital
1001110 4E 78 N
letters
Capital
1001111 4F 79 O
letters
Capital
1010000 50 80 P
letters
Capital
1010001 51 81 Q
letters
Capital
1010010 52 82 R
letters
Capital
1010011 53 83 S
letters
Capital
1010100 54 84 T
letters
Capital
1010101 55 85 U
letters
Capital
1010110 56 86 V
letters
Capital
1010111 57 87 W
letters
15
Hexa ASCII
Binary Decimal Description Group
decimal Symbol
Capital
1011000 58 88 X
letters
Capital
1011001 59 89 Y
letters
Capital
1011010 5A 90 Z
letters
Special
1011011 5B 91 [ Left square bracket
character
Special
1011100 5C 92 \ Inverse/backward slash
character
Special
1011101 5D 93 ] Right square bracket
character
Special
1011110 5E 94 ^ Circumflex
character
Special
1011111 5F 95 _ Underscore
character
Special
1100000 60 96 ` Gravis (backtick)
character
Lowercase
1100001 61 97 a
letters
Lowercase
1100010 62 98 b
letters
Lowercase
1100011 63 99 c
letters
Lowercase
1100100 64 100 d
letters
Lowercase
1100101 65 101 e
letters
Lowercase
1100110 66 102 f
letters
Lowercase
1100111 67 103 g
letters
Lowercase
1101000 68 104 h
letters
Lowercase
1101001 69 105 i
letters
Lowercase
1101010 6A 106 j
letters
Lowercase
1101011 6B 107 k
letters
Lowercase
1101100 6C 108 l
letters
Lowercase
1101101 6D 109 m
letters
16
Hexa ASCII
Binary Decimal Description Group
decimal Symbol
Lowercase
1101110 6E 110 n
letters
Lowercase
1101111 6F 111 o
letters
Lowercase
1110000 70 112 p
letters
Lowercase
1110001 71 113 q
letters
Lowercase
1110010 72 114 r
letters
Lowercase
1110011 73 115 s
letters
Lowercase
1110100 74 116 t
letters
Lowercase
1110101 75 117 u
letters
Lowercase
1110110 76 118 v
letters
Lowercase
1110111 77 119 w
letters
Lowercase
1111000 78 120 x
letters
Lowercase
1111001 79 121 y
letters
Lowercase
1111010 7A 122 z
letters
Special
1111011 7B 123 { Left curly bracket
characters
Special
1111100 7C 124 l Vertical line
characters
Special
1111101 7D 125 } Right curly brackets
characters
Special
1111110 7E 126 ~ Tilde
characters
The DEL (Delete) symbol deletes a
character. This is a control character Control
1111111 7F 127 DEL
that consists of the same number in all characters
positions.
17
Example 1: (10010101100001111011011000011010100111000011011111101001 1101110 11101
001000000011000101100100110011)2
Step 1: In the first step, we we make the groups of 7-bits because the ASCII code is 7 bit.
1001010 1100001 1110110 1100001 1010100 1110000 1101111 1101001 1101110 1110100 1000000
0110001 0110010 0110011
Step 2: Then, we find the equivalent decimal number of the binary digits either from the ASCII table
or 64 32 16 8 4 2 1 scheme.
BINARY DECIMAL
64 32 16 8 4 2 1
64+8+2=74
1 0 0 1 0 1 0
64 32 16 8 4 2 1
64+32+1=94
1 1 0 0 0 0 1
64 32 16 8 4 2 1
64+32+16+4+2=118
1 1 1 0 1 1 0
64 32 16 8 4 2 1
64+32+1=97
1 1 0 0 0 0 1
64 32 16 8 4 2 1
64+16+4=84
1 0 1 0 1 0 0
64 32 16 8 4 2 1
64+32+16=112
1 1 1 0 0 0 0
64 32 16 8 4 2 1
64+32+8+4+2+1=111
1 1 0 1 1 1 1
64 32 16 8 4 2 1
64+32+8+1=105
1 1 0 1 0 0 1
64 32 16 8 4 2 1
64+32+8+4+2=110
1 1 0 1 1 1 0
64 32 16 8 4 2 1
64+32+16+4=116
1 1 1 0 1 0 0
64 32 16 8 4 2 1
64
1 0 0 0 0 0 0
64 32 16 8 4 2 1
32+16+1=49
0 1 1 0 0 0 1
64 32 16 8 4 2 1
32+16+2=50
0 1 1 0 0 1 0
64 32 16 8 4 2 1
32+16+2+1=51
0 1 1 0 0 1 1
18
Step 3: Last, we find the equivalent symbol of the decimal number from the ASCII table.
19
Logic Gates:
Logic gates are the digital circuits capable of performing a particular logic function
by operating on a number of binary inputs.
OR
Logic gates are the basic building blocks of any digital circuit.
20
1. BASIC LOGIC GATES:
1. AND Gate
The output of AND gate is high (‘1’) if all of its inputs are high (‘1’).
The output of AND gate is low (‘0’) if any one of its inputs is low (‘0’).
Logic Symbol
Truth Table
A B Y = A.B
0 0 0
0 1 0
1 0 0
1 1 1
21
2. OR Gate
The output of OR gate is high (‘1’) if any one of its inputs is high (‘1’).
The output of OR gate is low (‘0’) if all of its inputs are low (‘0’).
Logic Symbol
Truth Table
A B Y=A+B
0 0 0
0 1 1
1 0 1
1 1 1
22
3. NOT Gate
The output of NOT gate is high (‘1’) if its input is low (‘0’).
The output of NOT gate is low (‘0’) if its input is high (‘1’).
From here
It is clear that NOT gate simply inverts the given input.
Since NOT gate simply inverts the given input, therefore it is also known as Inverter Gate.
Logic Symbol
Truth Table
A Y = A’
0 1
1 0
23
2. UNIVERSAL LOGIC GATES:
Universal logic gates are the logic gates that are capable of implementing
any Boolean function without requiring any other type of gate.
1. NAND Gate
2. NOR Gate
24
1. NAND Gate
A NAND Gate is constructed by connecting a NOT Gate at the output terminal of the AND
Gate.
The output of NAND gate is high (‘1’) if at least one of its inputs is low (‘0’).
The output of NAND gate is low (‘0’) if all of its inputs are high (‘1’).
Logic Symbol
Truth Table
A B Y = (A.B)’ OR Y = (A.B)
0 0 1
0 1 1
1 0 1
1 1 0
25
2. NOR Gate
A NOR Gate is constructed by connecting a NOT Gate at the output terminal of the OR Gate.
The output of OR gate is high (‘1’) if all of its inputs are low (‘0’).
The output of OR gate is low (‘0’) if any of its inputs is high (‘1’).
Logic Symbol
Truth Table
A B Y = (A+B)’ OR Y= (A+B)
0 0 1
0 1 0
1 0 0
1 1 0
26
3. OTHER LOGIC GATES:
1. XOR Gate
The Exclusive-OR or ‘Ex-OR’ gate is a digital logic gate with more than two inputs and
gives only one output.
The output of XOR Gate is ‘High’ if either input is ‘High’.
The output is ‘Low’ if both the inputs are ‘High’ or if both the inputs are ‘Low’.
The symbol and truth table of the XOR gate can be shown as:
A B Y
0 0 0
1 0 1
1 1 0
27
2. XNOR Gate
The Exclusive-NOR or ‘EX-NOR’ gate is a digital logic gate with more than two inputs
and gives only one output.
The output of XNOR Gate is ‘High’ if both the inputs are ‘High’ or if both the
inputs are ‘Low.’
The output is ‘Low’ if either of the input is ‘Low’.
The symbol and truth table of an XNOR gate can be given a s:
Logical Symbol of XNOR Gate
A B Y
0 0 1
0 1 0
1 1 1
28
REALIZATION OF LOGIC FUNCTIONS WITH THE HELP OF UNIVERSAL GATES-
NAND GATE
NAND gate is actually a combination of two logic gates: AND gate followed by NOT gate.
This gate can have minimum two inputs, output is always one. By using only NAND gates,
we can realizeall logic functions: AND, OR, NOT, X-OR, X-NOR, NOR. So this gate is also
called universal gate.
A NOT produces complement of the input. It can have only one input, tie the inputs of a NAND
gate together.Now it will work as a NOT gate. Its output is
Y = (A.A)’
=> Y = (A)’
A NAND produces complement of AND gate. So, if the output of a NAND gate is inverted, overall
output will bethat of an AND gate.
Y = ((A.B)’)’
=> Y = (A.B)
29
3. NAND gates as OR gate
30
5. NAND gates as X-OR gate
The output of a two input X-OR gate is shown by: Y = A’B + AB’.
This can be achieved with the logic diagram shown in the left side.
31
6. NAND gates as X-NOR gate
32
REALIZATION OF LOGIC FUNCTIONS WITH THE HELP OF UNIVERSAL GATES-
NOR GATE
Y = (A+A)’
=> Y = (A)’
Y = ((A+B)’)’
=> Y = (A+B)
33
3. NOR gates as AND gate
Y = (AB)’
34
5.NOR gates as X-OR gate
Y = A’B+ AB’
35
6. NOR gates as X-NOR gate
Now the output from gate no. 4is the overall output of the configuration.
Y = ((A + (A+B)’)’ (B +( A+B)’)’)’
= (A+(A+B)’)’’.(B+(A+B)’)’’
= (A+(A+B)’).(B+(A+B)’)
= (A+A’B’).(B+A’B’)
= (A + A’).(A + B’).(B+A’)(B+B’)
= 1.(A+B’).(B+A’).1
= (A+B’).(B+A’)
= A.(B + A’) +B’.(B+A’)
= AB + AA’ +B’B+B’A’
= AB + 0 + 0 + B’A’
= AB + B’A’
=> Y = AB + A’B’
36
37