0% found this document useful (0 votes)
7 views

CODES

Uploaded by

d.mohithakshay
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

CODES

Uploaded by

d.mohithakshay
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 26

DIGITAL ELECTRONICS

Chapter Codes

Reference:
1. Malvino and Leach, Digital Principles & applications, 7th
edition, TMH, 2010
2. Morris Mano, “Digital design”, Prentice Hall of India, Third
Edition.

Department of Electronics and Communication Engineering, MIT, Manipal


Module 2: Codes

Learning outcomes

• Discuss different types of weighted and non weighted codes.


• Explain error detection using parity bit.
• Describe error correction using hamming code.

Department of Electronics and Communication Engineering, MIT, Manipal


Codes

 When numbers, letters or words are represented as a specific


group of symbols based on certain rules, it is said to be
encoded. The group of symbols is called a code.

 Codes are represented, stored and transmitted in the form of


binary bits. The codes may also use alpha numeric characters.

 Advantages of Binary Code:


Suitable for computer applications.
Used in digital communications.
Ease of circuit implementation.

Department of Electronics and Communication Engineering, MIT, Manipal


Classification of binary codes:

 Generally codes are classified into following categories,

Weighted Codes
Non-Weighted Codes
Alphanumeric Codes
Error Detecting Codes
Error Correcting Codes

Department of Electronics and Communication Engineering, MIT, Manipal


Binary coded decimal codes

Weighted codes:

 Binary codes which obey the positional weight


principle.

 Each position of the bit or digit in the code has a


specific weight.

 Decimal digits 0-9 can be represented using 4 bit binary


code.

Department of Electronics and Communication Engineering, MIT, Manipal


Binary coded decimal codes

Weighted codes:

4 bit code: a3 a2 a1 a0

If W3, W2, W1 and W0 are the weights associated with 4 bits


Then
(A)10 = W3a3 + W2a2 + W1a1 +W0a0

The more popularly used codes have these weights as


W3 W2 W1 W0

8 4 2 1
2 4 2 1
8 4 -2 -1
Department of Electronics and Communication Engineering, MIT, Manipal
Binary coded decimal codes

Weighted codes:

Department of Electronics and Communication Engineering, MIT, Manipal


Binary coded decimal codes

Non-Weighted Code :The one in which the positions in the


code do not have a specific weight.
Examples:
EXCESS-3 CODE
GRAY CODE
 EXCESS-3 CODE: The Excess-3 code words are derived from
the 8421 BCD code words by adding (0011)2 or (3)10 to each code
word in 8421.

 GRAY CODE: The essential feature of a Gray code is that there


is only a single bit difference between successive code words.
• Also called Unit distance code/ Minimum error code/
Reflected binary code
Department of Electronics and Communication Engineering, MIT, Manipal
Binary coded decimal codes
8421, 2421, Excess-3 and Gray code
Decimal BCD = 8421 2421 Excess-3 Gray
0 0000 0000 0011 0000
1 0001 0001 0100 0001
2 0010 0010 0101 0011
3 0011 0011 0110 0010
4 0100 0100 0111 0110
5 0101 1011 1000 0111
6 0110 1100 1001 0101
7 0111 1101 1010 0100
8 1000 1110 1011 1100
9 1001 1111 1100 1101

Department of Electronics and Communication Engineering, MIT, Manipal


 Gray code: (2-BIT) GRAY CODE: (3-BIT)
 00 000
 01 001
 11 011
 10 010
110
111
101
 100

Department of Electronics and Communication Engineering, MIT, Manipal


Binary to Gray code conversion:

 Bn Bn-1 . . . . B1
 Gn Gn-1 . . . . G1 ?

 Formulae:
 Gn = Bn ; Gn-1 = Bn XOR Bn-1 ….. G1 = B2 XOR B1

Problem: (1001)2 = ( ? )GRAY


 1 0 0 1 (Binary)
 ?
 1 1 0 1 (Gray)

Department of Electronics and Communication Engineering, MIT, Manipal


GRAY TO BINARY CONVERSION:

 Gray code: Gn Gn-1 ………G1


 Binary code: Bn Bn-1 ……….B1 ?

 FORMULAE:
 Bn = Gn ; Bn-1 = Bn XOR Gn-1 ….. B1 = B2 XOR G1

Problem: (1 1 0 1)GRAY = ( ? )2
 GRAY: 1 1 0 1
 ?
 BINARY: 1 0 0 1

Department of Electronics and Communication Engineering, MIT, Manipal


Self complementing codes

Self-complementing code:
 A code is said to be self-complementing, if the code word of the
9’s complement of N can be obtained from the code word of N
by converting all the 0’s into 1’s and all 1’s into 0’s.

 2421 and Excess 3 codes are self complementing codes.

Consider 2421 code.

The 2421 code of (4)10 is: 0100

Its 1s complement is 1011

1011 is the 2421 code for (5)10 = (9 - 4)10.

Department of Electronics and Communication Engineering, MIT, Manipal


Error Detecting and Correcting codes

Error Detection and Correction:

• Single bit Error detection using parity bit


• Single bit error correction using (7,4) Hamming code

Department of Electronics and Communication Engineering, MIT, Manipal


Introduction

• When data is transmitted in digital form from transmitter to the


receiver through a transmission channel some data bits may be
modified.
0 0 1 1 (Tx) Fiber Optics 0 1 1 1 (Rx)

• Ability to identify the error is called the error detection.

• A code which has the ability to correct the data is called


error correction code.

Department of Electronics and Communication Engineering, MIT, Manipal


Error detection code:

Parity bit: It is the extra bit added to each word


being transmitted.

1. Odd parity system and 2. Even parity


System.
 Odd parity: The parity bit is set to 0 or 1 at the
transmitter such that the total number of 1 bit in the
word including the parity bit is an odd number.

 Even parity: The parity bit is set to 0 or 1 at the


transmitter such that the total number of 1 bit in the
word including the parity bit is an even number.

Department of Electronics and Communication Engineering, MIT, Manipal


ODD PARITY & EVEN PARITY BIT FOR 4-BIT WORD
Decimal 8 4 2 1 Odd Even
No. BCD Parity Parity
(P) (P)
0 0000 1 0
1 0001 0 1
2 0010 0 1
3 0011 1 0
4 0100 0 1
5 0101 1 0
6 0110 1 0
7 0111 0 1
8 1000 0 1
9 1001 1 0
Hamming Code

 The most common types of error-correcting codes used in


RAM are based on the codes devised by R.W. Hamming.

 K parity bits are added to an n-bit data word, forming a new


word of n + k bits.

 The bit positions are numbered in sequence from 1 to n + k.

 Those positions numbered with powers of two are reserved


for the parity bits.

 The code can be used with words of any length.

Department of Electronics and Communication Engineering, MIT, Manipal


7-bit Hamming Code

 To transmit 4 data bits, 3 parity bits are located at positions 20,


21 and 22 to make 7-bit code word which is then transmitted.

 The word format is,


B1 B2 B3 B4 B5 B6 B7

P1 P2 D3 P3 D2 D1 D0

Department of Electronics and Communication Engineering, MIT, Manipal


7-bit Hamming Code

 Calculating parity bits,


B 3 ⨁ B5 ⨁ B7

B 3 ⨁ B6 ⨁ B7
B 5 ⨁ B6 ⨁ B7

 Checking,

B 1 ⨁ B3 ⨁ B5 ⨁ B7

B 2 ⨁ B3 ⨁ B6 ⨁ B7

B 4 ⨁ B5 ⨁ B6 ⨁ B7

Department of Electronics and Communication Engineering, MIT, Manipal


7 Bit Hamming Code
 Error Detection and Correction: (Receiver section)

C1 = [P1 , D3, D2 , D0]


C2 = [P2 , D3, D1 , D0]
C3 = [P4 , D2, D1 , D0]

 Cn which is the output of the parity checker is made 0 if the


total no. of 1s in the 4-bit word is even. Else Cn is made 1.

 [C3, C2, C1] gives the location at which error occurred.


To correct the data, complement the bit.

Department of Electronics and Communication Engineering, MIT, Manipal


7 Bit Hamming Code

 7 bit Even Parity Hamming code: ( 4 bit data and 3


bit parity)
 Problem: Encode the data 1101 into 7 bit even parity
Hamming code.
P1 P2 D3 P3 D2 D1 D0
1 1 0 1
 Bits P1,D3,D2,D0 (i.e. P1 1 1 1) must be even parity. So P1
must be 1.
 Bits P2,D3,D1,D0 (i.e. P2 1 0 1) must be even parity. So P2
must be 0.
 Bits P4,D2,D1,D0 (i.e. P4 1 0 1) must be even parity. So P4
must be 0.
 Hence the 7-bit code is 1 0 1 0 1 0 1
Department of Electronics and Communication Engineering, MIT, Manipal
Example: If the transmitted code P1 P2 D3 P4 D5 D6 D7:
1 0 1 0 1 0 1

Is received it as: 1 0 1 0 0 0 1
i.e. D5 gets corrupted.

C1 = [P1 , D3, D5 , D7] = [1 1 0 1] ; C1 = 1

C2 = [P2 , D3, D6 , D7] = [0 1 0 1] ; C2 = 0

C3 = [P4 , D5, D6 , D7] = [0 0 0 1] ; C3 = 1

[C3 C2 C1] = [ 1 0 1]2 = (5)10 means error at position 5. (From left)

Error Report:D5 gets corrupted. Correct D5 as 1

Department of Electronics and Communication Engineering, MIT, Manipal


Problem: Encode data bits 0101 into 7 bit even parity
Hamming code.
Ans. 0 1 0 0 1 0 1

Department of Electronics and Communication Engineering, MIT, Manipal


 Soln.
 Data Given:0 1 0 1
 7-Bit even parity Hamming code:

P1 P2 D3 P4 D5 D6 D7
0 1 0 1
0
1
0

0 1 0 0 1 0 1
7-bit Hamming code:

Department of Electronics and Communication Engineering, MIT, Manipal

You might also like