Unit 1 Codes
Unit 1 Codes
Text Books:
1. R.P. Jain, “Modern Digital Electronics”, Tata McGraw Hill Publication, 4th Edition, 2010.
2. M. M. Mano, “Digital Logic and Computer Design”, Prentice Hall of India Publication, 4 th
Edition, 2006.
Reference Books:
1. D. P. Leach, A. P. Malvino, G. Saha, “Digital Principles and Applications”,Tata McGraw Hill
Publication, 8th Edition, 1993.
2. Comer, “Digital Logic & State Machine Design”, Oxford Universities Press, 3rd Edition,
2014
E-Sources:
NPTEL videos
Codes
Computers and other digital circuits process data
in the binary format.
Various binary codes are used to represent data
which may be numeric, alphabets or special
characters.
Codes are also used for error detection and error
correction in digital systems.
Straight Binary Code:
This is used to represent numbers using natural binary
form, various arithmetic operations can be performed
in this form
Natural BCD Code
In this code, decimal digits 0 through 9 are represented by their
natural binary equivalents using 4 bits and each decimal digit of a
decimal number is represented by this 4 bit code individually.
For ex. (23)10 is represented by 0010 0011 using BCD code
rather than (100011)2
It requires more number of bits to code a decimal number using
BCD code than using a straight binary code but useful for input
and output operations in digital systems
This code is also known as 8-4-2-1code or simply BCD code
8-4-2-1 are the weights of the four bits of the binary code of
each decimal digit similar to straight binary number system
Therefore this is a weighted code and arithmetic operations can
be performed using this code
Various Binary Codes
Excess-3 Code
In this code each decimal digit is coded into a 4-bit binary
code
The code for each decimal digit is obtained by adding
decimal 3 to the natural BCD code of the digit
For ex. Decimal 2 is coded as 0010+0011=0101in Excess-3
code
It is not a weighted code rather a self complementing code
which means 1’sC of the coded number yields 9’s
complement of the number itself.
Decimal Excess-3 code 1’sC 9’sC
For ex. Number
2 0101 1010 1010
… … … …
7 1010 … …
Gray Code
A decimal number represented in binary form in such a way that each gray code
number differs from the preceding and the succeeding number by a single bit.
Decimal Number Binary number Gray Code
5 0101 0111
6 0110 0101
These two codes differ by only one bit position (third from left).
It is not a weighted code.
Gray codes can be created using following properties:
A 1 bit Gray code has two code words 0 and 1 representing decimal numbers 0
and 1 resp.
An n bit (n>=2) Gray code will have first 2 n-1 Gray codes of (n-1) bits written in
order with a leading 0 appended.
The last 2n-1 Gray codes will be equal to the Gray code words of an (n-1) bit
Gray code, written in reverse order (assuming a mirror placed between first and
last 2n-1 and last 2n-1 Gray codes) with a leading 1 appended.
Various Binary Codes
Octal Code
It is a 3-bit binary code, in which each of the octal digits 0
through 7 is coded into 3 bit straight binary number.
For ex. Octal digit 4 is coded as 100
This code is used for binary inputs in digital computers,
microprocessors etc.
Hexadecimal Code
It is a 4-bit binary code used for input/output in digital
computers, microprocessors etc.
Hexadecimal Code
It is a 4-bit binary code used for input/output in digital
computers, microprocessors etc.
Hexadecimal Code
It is a 4-bit binary code used for input/output in digital
computers, microprocessors etc.
Hexadecimal Code
It is a 4-bit binary code used for input/output in digital
computers, microprocessors etc.
Hexadecimal Code
It is a 4-bit binary code used for input/output in digital
computers, microprocessors etc.
Hexadecimal Code
It is a 4-bit binary code used for input/output in digital
computers, microprocessors etc.
Hexadecimal Code
It is a 4-bit binary code used for input/output in digital
computers, microprocessors etc.
Alphanumeric Codes
Digital systems are required to handle data that may consist of
numerals, letters and special symbols.
If we use an n-bit binary code, we can represent 2 n elements using
this code.
So, to represent 10 digits, 0 through 9 and 26 alphabets A through Z,
minimum of 6 bits.
One possible 6 bit alphanumeric code is given in following table.
This is also called as internal code.
Frequently there is a need to represent more than 64 characters
including the lowercase letters and special control characters for
the transmission of digital information.
Following codes are used for this reason:
Extended BCD Interchange Code (EBCDIC)
American Standard Code for Information Interchange (ASCII)
Some Alphanumeric Codes
Some Alphanumeric Codes
The ASCII Code
Error Detecting and Correcting Codes
Digital signals are processed for performing various operations
and are transmitted from one circuit or system to another
circuit or system.
When these binary signals are transmitted from one location
(transmitter) to another (receiver), transmission error may
occur because of electrical noise in the transmission channel.
Due to transmission error a signal transmitted as a 0 may be
received as a1or vice versa.
The probability of occurrence of error in two or more bit
positions is smaller.
It is desired to detect the error in the received data word,
locate its bit position and correct it.
Various codes are used for the detection and correction of
error.
Error Detecting Codes
When a digital information is transmitted, it may not be
received correctly by the receiver.
At the receiving end it may or may not be possible to
detect whether the information has been received
correctly or not.
Decimal Binary code Received BCD Code
Error
Number transmitted code (Valid / Invalid)
9 1001 1011 Invalid BCD Code Error detected
Valid BCD Code Error not
9 1001 0001
for decimal-1 detected
Error Detecting Codes
For an n-bit code there are 2n possible combinations, therefore, if it
is desired to make this code an error detecting code, only half of the
possible 2n combinations should be included to form the code.
If an extra bit is attached to the n bit code word to make the
number of bits n+1 in such a way so as to make the number of ones
in the resulting (n+1) bit code even or odd, it will certainly be an
error detecting code.
The criterion of minimum distance code can also be used as
useful property of an error detecting code.
The minimum distance of a code is the smallest number of bits in
which any two code words differ.
A code is an error detecting code if and only if its minimum
distance is two or more.
For detection of error an extra bit known as parity bit is
attached to each code word to make the number of ones in
the code even (even parity) or (odd parity).
BCD Code with Parity Bit
BCD Code with Parity Bit
BCD Code with Parity Bit
BCD Code with Parity Bit
BCD Code with Parity Bit
BCD Code with Parity Bit
Error Detecting Codes
A parity bit (P) 0 or 1 is attached to every code word so as to make
the number of ones even or odd for even and odd parity resp.
It can be easily verified that the minimum distance between any two
code words with parity bit attached is two.
The parity bit 1or 0 is attached to the code to be
transmitted at the transmitter end and the parity of the
received (n+1)-bit word is checked at the receiving end.
If there is only one error the erroneous code is detected at the
receiving end by parity check.
If odd number of bits are transmitted erroneously then also the
parity check will detect the incorrect code but if there are even
number of bits received incorrectly this method will not detect
error.
The parity check method can only detect error in the transmitted
word at the receiving end.
It cannot locate the bit which has changed and therefore the
question of correction does not arise.
The ASCII Code
Error Correcting Codes
By adding a single parity bit along with the information, or
message being transmitted, an error in single bit position can
be detected.
The parity check gives only information that the received
message is incorrect.
It cannot locate the bit position in which error has occurred
and therefore cannot correct the error.
Ex1. Suppose a 4-bit binary word 0101 is transmitted along
with an even parity bit
Erroneous words received may be:
00100 error in b0
00111 error in b1
00001 error in b2
01101 error in b3
Error Correcting Codes
Ex2. Suppose a word 01100 is transmitted
Erroneous words received may be:
00100 error in b3
This indicates that a minimum distance of two cannot locate the bit position
in the incorrectly received word.
So, for a code to be error correcting, its minimum distance must be more
than two.
If the minimum distance is three, every error in single bit results in
an invalid code word which is at a distance of one from the original
code word and at a distance of two from any other valid code word.
So, a single bit error can be detected and located using this code.
Once the error bit is located it can be inverted to correct the erroneously
received message.
The capability of a code to be error detecting and/or error correcting can be
determined from its minimum distance.
If a code’s minimum distance is 2c+d+1, it can correct errors in up
to c bits and detect errors in up to d additional bits.
Following table gives possible values of c and d for various values of minimum
distance of a code.
Error Correcting Codes