Nothing Special   »   [go: up one dir, main page]

ETU 07322 Lecture 1 - 2

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

Lecture 1_2: Fundamentals of Digital

Electronics

CODES

MDK 1
Overview
• In the coding, when numbers, letters or words are represented by a specific
group of symbols, it is said that the number, letter or word is being encoded.
• The group of symbols is called as a code.
• The digital data is represented, stored and transmitted as group of binary
bits.
• This group is also called as binary code.
• A binary code represents text, computer processor instructions, or any other
data using a two-symbol system often "0" and "1" from the binary number
system.
• The binary code is represented by the number as well as alphanumeric letter
and , instruction, etc.

MDK 2
Overview
• Human perception naturally live in a base 10 environment
• Computer exist in a base 2 environment
• So give the computer/digital system the task of doing the conversions
for us.

MDK 3
Classification of binary codes
• The codes are broadly categorized into following four categories.
• Weighted Codes
• Binary Coded Decimal Code
• Alphanumeric Codes
• Non-Weighted Codes
• Excess-3 code
• Gray code
• Error Detecting Codes
• Error Correcting Codes

MDK 4
Weighted Codes
• Weighted binary codes are those binary codes which obey the
positional weight principle.
• Each position of the number represents a specific weight.
• Several systems of the codes are used to express the decimal
digits 0 through 9.
• In these codes each decimal digit is represented by a group of
four bits.

MDK 5
Binary Coded Decimal (BCD) code
• In this code each decimal digit is represented by a 4-bit binary number.
BCD is a way to express each of the decimal digits with a binary code.
• With four bits we can represent sixteen numbers (0000 to 1111).
• But in BCD code only first ten of these are used (0000 to 1001).
• The remaining six code combinations i.e. 1010 to 1111 are invalid in
BCD.

MDK 6
Binary Coded Decimal
Digit BCD Digit BCD
Code Code
0 0000 5 0101
1 0001 6 0110
2 0010 7 0111
3 0011 8 1000
4 0100 9 1001

• Binary coded decimal (BCD) represents each decimal


digit with four bits
• Ex. 0011 0010 1001 = 32910
3 2 9
• This is NOT the same as 0011001010012
• Why do this? Because people think in decimal.

MDK 7
BCD code advantages and disadvantages
• Advantages of BCD Codes
• It is very similar to decimal system.
• We need to remember binary equivalent of decimal numbers 0 to 9 only
• Disadvantages of BCD Codes
• The addition and subtraction of BCD have different rules.
• The BCD arithmetic is little more complicated.
• BCD needs more number of bits than binary to represent the decimal number.
So BCD is less efficient than binary

MDK 8
Putting It All Together

° BCD not very efficient


° Used in early computers
(40s, 50s)
° Used to encode numbers
for seven-segment
displays.

MDK 9
Alphanumeric codes
• A binary digit or bit can represent only two symbols as it has only two
states '0' or '1'.
• But this is not enough for communication between two computers
because we need many more symbols for communication.
• These symbols are required to represent 26 alphabets with capital and
small letters, numbers from 0 to 9, punctuation marks and other
symbols.
• These codes are used to encode the characteristics of alphabet in
addition to the decimal digits. It is used for transmitting data between
computers & its I/O device such as printers, keyboards & video
display terminals.
MDK 10
Alphanumeric codes
• The following three alphanumeric codes are very commonly used for
the data representation.
• American Standard Code for Information Interchange (ASCII).
• Extended Binary Coded Decimal Interchange Code (EBCDIC).
• Five bit Baudot Code.
• ASCII code is a 7-bit code whereas EBCDIC is an 8-bit
code.
• ASCII code is more commonly used worldwide while
EBCDIC is used primarily in large IBM computers.

MDK 11
ASCII Code
• American Standard Code for Information
Interchange(ASCII) is a 7-bit code.
• The code uses 7 bits to encode 128 unique characters
Characte ASCII ASCII Decimal Octal
r (bin) (hex)
A 1000001 41 65 101
B 1000010 42 66 102
C 1000011 43 67 103

Z
a

1

MDK 12
Non-Weighted Codes
• In this type of binary codes, the positional weights are not assigned.
• The examples of non-weighted codes are Excess-3 code and Gray
code.
• The Excess-3 code words are derived from the 8421 BCD code words
adding (0011)2 or (3)10 to each code word in 8421.

MDK 13
Excess-3 code
Decimal BCD Excess-3
• The excess-3 codes are obtained
8+4+2+1 BCD+0011
as follows.
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

MDK 14
Gray Codes
• Gray code is a non-weighted code
• It is an alternate way to represent four bit data
• Only one bit will change each time the decimal number is
incremented as shown in fig.
• Useful for reducing errors in communication.
• The gray code is a cyclic code. It is referred to as cyclic
because successive code words in this code differ by only one
bit-position.
• Gray code cannot be used for arithmetic operation
MDK 15
Gray Code
Digit Binary Gray 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 1010 1111
11 1011 1110
12 1100 1010
13 1101 1011
14 1110 1001
15 1111 1000 MDK 16
Gray Codes
Application of Gray code
• Gray code is popularly used in the shaft position encoders.
• A shaft position encoder produces a code word which represents the
angular position of the shaft
• In many practical applications such as analog to digital conversion,
unit distance codes are used

MDK 17
Conversion of Gray Code into Binary Number

• The MSB of Gray code is copied as it to be the MSB bit of binary


number which is then XORed with the next bot of gray code, the result
is recorded as the next bit of binary number, now this recorded bit is
XORed with the next bit of gray code and this process is continued till
the LSB is obtained.

MDK 18
Conversion from BCD to gray code

• Now, the MSB of the binary number is copied as it is and then we


perform XOR operation for consecutive bits in a pair of two.
• To convert Binary Code into Gray Code, one should have knowledge
of truth table of XOR Gate which is as,

MDK 19
Error Detection & Correction Codes

• The bits 0 and 1 corresponding to two different range of analog


voltages.
• During transmission of binary data from one system to the other, the
noise may also be added.
• That means a bit 0 may change to 1 or a bit 1 may change to 0.
• To get back the original data, the following codes can be use:
• Error detection codes
• Error correction codes

MDK 20
ERROR CORRECTION CODES

Error – Detecting codes


When binary data is transmitted & processed, it is susceptible to noise
that can alter or distort its contents. The 1‘s may get changed to 0‘s &
1‘s .because digital systems must be accurate to the digit, error can pose
a problem. Several schemes have been devised to detect the occurrence
of a single bit error in a binary word, so that whenever such an error
occurs the concerned binary word can be corrected & retransmitted
MDK 21
Error Detection & Correction Codes

• Error detection codes − are used to detect the errors present in the
received data bit stream. These codes contain some bits , which are
included appended to the original bit stream. These codes detect the
error, if it is occurred during transmission of the original data bit
stream. Example − Parity code, Hamming code.
• Error correction codes − are used to correct the errors s present in the
received data bit stream so that, we will get the original data. Error
correction codes also use the similar strategy of error detection codes.
Example − Hamming code.
• Therefore, to detect and correct the errors, additional bits are
appended to the data bits at the time of transmission.

MDK 22
Error-Correcting Codes

• Error correcting codes not only detect errors, but also correct them.
This is used normally in Satellite communication, where turn-around
delay is very high as is the probability of data getting corrupt.
• Error correcting codes(ECC) are used also in memories, networking,
Hard disk, CDROM, DVD etc. Normally in networking chips , we
have 2 Error detection bits and 1 Error correction bit

MDK 23
Parity Code
• If the other system receives one of these even/odd parity codes, then
there is no error in the received data.
• The bits other than even/odd parity bit are same as that of binary code.
• If the other system receives other than even/odd parity codes, then
there is an errors s in the received data. In this case, we can’t predict
the original binary code because we don’t know the bit positions s of
error.
• Therefore, even/odd parity bit is useful only for detection of error in
the received parity code. But, it is not sufficient to correct the error.

MDK 24
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.
Even Parity Code
• 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.
Odd Parity Code
• 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.

MDK 25
Parity Codes
• Parity codes are formed by concatenating a parity bit, P to
each code word of C.
• In an odd-parity code, the parity bit is specified so that the
total number of ones is odd.
• In an even-parity code, the parity bit is specified so that the
total number of ones is even.

P Information Bits
1 1 0 0 0 0 1 1 0 1 0 0 0 0 1 1
 
Added even parity bit Added odd parity bit

MDK 26
Parity Code Example
• Concatenate a parity bit to the ASCII code for the characters 0,
X, and = to produce both odd-parity and even-parity codes.

Character ASCII Odd-Parity Even-Parity


ASCII ASCII

0 0110000 10110000 00110000

X 1011000 01011000 11011000

= 0111100 10111100 00111100

MDK 27
MDK 28
Class exercise
• Discuss about Hamming code as an Error Detection & Correction
Code .

MDK 29

You might also like