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

Excess Code_gray code,paritycode

The document discusses various coding systems used in digital circuits, including Binary Coded Decimal (BCD), Excess-3 code, Gray code, and error detection methods like parity codes and Hamming codes. It explains how BCD represents decimal digits in binary, the properties of Gray code, and the principles behind error detection and correction using Hamming codes. Additionally, it covers the conversion processes between binary and Gray code, as well as the importance of minimum distance in error detection codes.

Uploaded by

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

Excess Code_gray code,paritycode

The document discusses various coding systems used in digital circuits, including Binary Coded Decimal (BCD), Excess-3 code, Gray code, and error detection methods like parity codes and Hamming codes. It explains how BCD represents decimal digits in binary, the properties of Gray code, and the principles behind error detection and correction using Hamming codes. Additionally, it covers the conversion processes between binary and Gray code, as well as the importance of minimum distance in error detection codes.

Uploaded by

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

DE Lec5

BCD and Gray code representations and Error Detecting code and
Hamming code
Codes
• Computer/digital circuits process data in binary format.
• Binary data is usually represented using particular format/code
• For example , (1000001)2 is represented as
• ______ in binary
• ______ in BCD
• _______ in ASCII code
Binary coded decimal (BCD) number representation
• It is sometimes desirable to manipulate numbers in decimal instead of
converting them binary .
- Decimal to binary and binary to decimal conversion process is complex.
• One popular code to represent decimal digits is BCD.
• Each decimal digit is represented by its 4 bit equivalent
• Conversion is much easier
• Examples
• Decimal 238 BCD: 0010 0011 1000 The six 4 bit combinations
1010,1011,1100,1101,1110 and
• Decimal 12.39 BCD:0001 0010 . 0011 1001 1111 are unused
BCD Binary

0 0000

1 0001

2 0010

3 0011

4 0100

5 0101

6 0110

7 0111

8 1000

9 1001
Addition of BCD numbers
• When we add two BCD numbers,we may have to go for a correction step
where 6(0110) is added to one of the nibbles.
1,Either when a nibble is one of the six invalid combinations, or
2, There is a carry in from the previous nibble.
• Examples
• 23+46 23+48 28+39
1

0010 0011 0010 0011 0010 1000


0100 0110 0100 1000 0011 1001
0110 1001 0110 1011 0110 0001
+0110 +0110
0111 0001 0110 0111
23+46, 23+48, 28+39, 26+49
Excess-3 code
• It is another form of BCD code where each decimal digit is coded into 4 bit
binary code.
• The code for each decimal digit is obtained by adding decimal 3 to the BCD
code of the digit.
• For example , Decimal 2 is coded as 0 0 1 0 in BCD
0 0 1 0 + 0 0 1 1 in Excess-3
=0101
• It is not weighted code
Excess – 3 code is ‘Self-complementing code’
• Logical complement of coded number (Here Excess-3) is the
arithmetic complement.
• 1’s complement of the coded number yields the 9’s complement of
the number itself.
• For Example:
Excess- 3 code of decimal ‘2’ is 0101
1’s complement is 1010 – Excess 3 of ‘7’
9’s complement of ‘2’ - ‘7’
Problem involved in Binary number system
0 0000 here one bit is
changing
1 0001 here two bits
are changing
2 0010
3 0011
4 0100
5 0101
Gray codes
• Gray code is a type of non weighted binary code where successive
code words differ in only one bit.
• Any code with this property is called cyclic codes
• Gray code is useful in many practical applications that require analog
to digital conversion
• To reduce error in conversion
• Also binary to gray or gray to binary is easy
4 bit binary to gray code
decimal Gray code Binary code decimal Gray code Binary code
g3 g2 g1 g0 b3 b2 b1 b0 g3 g2 g1 g0 b3 b2 b1 b0
0 0 0 0 0 0 0 0 0 8 1 1 0 0 1 0 0 0
1 0 0 0 1 0 0 0 1 9 1 1 0 1 1 0 0 1
2 0 0 1 1 0 0 1 0 10 1 1 1 1 1 0 1 0
3 0 0 1 0 0 0 1 1 11 1 1 1 0 1 0 1 1
4 0 1 1 0 0 1 0 0 12 1 0 1 0 1 1 0 0
5 0 1 1 1 0 1 0 1 13 1 0 1 1 1 1 0 1
6 0 1 0 1 0 1 1 0 14 1 0 0 1 1 1 1 0
7 0 1 0 0 0 1 1 1 15 1 0 0 0 1 1 1 1
Gray code is also called self reflecting code
- Suppose we have gray code representation for m bits
- To obtain the gray code representation for (m+1) bits we write down
two m bit representations one below the other with the second one
being the mirror image of the first one
- we then add the a 0 at the beginning of every code in the first group
and a 1 at the beginning of every code in the second group.
Example
00 0 00 0 000
01 0 01 0 001
11 0 11 0 011
10 0 10 0 010
0 110
0 111
0 101
1 10
0 100
1 11 Mirror image
1 01 1 100
1 00 1 101
1 111
1 110
1 010
3 bit gray code 1 011
1 001
1 000
4 bit gray code
Binary to gray code conversion
• Let gn-1 gn-2…………g2g1g0 and bn-1bn-2…..b2b1b0 denote n-bit gray code and its
binary equivalent respectively.
• gi = bi + bi+1, for 0≤i≤n-2
• gn-1=bn-1
• Here the symbol + denotes the modulo -2 sum defined as
• 0 + 0 = 0, 0 + 1 = 1, 1 + 0 = 1, 1 + 1 = 0
• As an example b5 b4 b3 b2 b1 b0
a b a +b 1 0 1 1 0 1
0 0 0
0 1 1 + + + + + +
1 0 1 1 1 1 0 1 1
•1 1 0 g5 g4 g3 g2 g1 go
Gray to binary conversion
• We start with the leftmost bit and proceed to the least significant bit
and set:
• bi = gi if no. of 1’s preceding gi is even
• bi = gi’ if no. of 1’s preceding gi is odd
01011001
Red indicates complimented

01101110
1,
2, How gray code is self-reflecting code?
Error Detection codes-parity codes
• Digital signals are processed and transmitted from one system to
another system.
• When these binary signals are transmitted from one location
(transmitter) to another location (receiver) , transmission error occur
because of electrical noise in the transmission channel.
• Because of this error 0 is detected as ‘1’ and ‘1’ is detected as ‘0’
• When codes like BCD , ASCII etc are transmitted there is always a
finite probability of occurrence of error in single bit.
• The probability of occurrence of error in two or more bit
simultaneously is substantially smaller
• If an occurrence of error is known, appropriate action, like
retransmitting the data, can be taken. One of the methods of
improving data integrity is to encode the data in a suitable manner.
Criteria of minimum distance of the
codeword
• It is useful property of error detecting code.
• The minimum distance of a code is smallest number of bits in which
any two code words differ. (= changes in number of bit position in two
codewords)
• Example: the minimum distance between 01001 and 11100 is
_______
Valid or invalid codeword
• For detecting single bit error, distance between a pair of codeword
must be atleast 2.
• For example: C1 : 1 0 0 0 1
C2 : 1 0 0 0 0
• Therefore, for detection of ‘k’ errors , distance must be at-least (k+1)

• For error correction of one bit , the distance must atleast 3.


Error detection codes – parity code
• A simple process of adding a special code bit to a data word can
improve its integrity.
• This extra bit will allow detection of a single error in a given code
word in which it is used, and is called the ‘Parity Bit’.
• Therefore the parity bit is the extra bit added to the message to make
total number of 1’s transmitted either even or odd
Parity code – even parity
• Assume that receiver does even parity check.
• Transmitter makes total number of 1s as even when there is even
parity check at the receiver. The transmitter will put 1 at i th extra
place if total number of ones at (i − 1) places is odd number. The
transmitter will put 0 at i th extra place if total number of ones at (i −
1) places is even number to maintain even parity in total i bits
transmitted
How we detect error?
Odd parity check
• Assume that receiver does odd parity check.
• Transmitter makes total number of 1s as odd when there is odd parity
check at the receiver. The transmitter will put 0 at i th extra place if
total number of ones at (i − 1) places is odd number. The transmitter
will put 1 at i th extra place if total number of ones at (i − 1) places is
even number to maintain odd parity in total i bits transmitted.
How to detect error?
Hamming code
• We have seen error detection code like parity code.
• Hamming code is used for error correction.
• For error correction of one bit , the minimum distance between codes
must atleast 3.
• Similarly for error correction of k bits, the minimum distance should
2k+1.
Basic principle of Hamming code
• If we have ‘m’ bit information, k parity bits are added to form (m+k)
bits
• Each of the (m+k) bits is assigned with a decimal value
1. MSB with ‘1’ , 2nd MSB with 2 ……………LSB with (m+k).
• k must satisfy the inequality 2𝑘 ≥ 𝑚 + 𝑘 + 1 (e.g for m=4,
smallest k should be 3)
• Parity check bits are assigned position numbers which are powers of 2
(1,2,4,8….. 2𝑘−1 )
• The parity check bits are calculated with the well defined formula.
Ex: Hamming code for BCD (m=4) For 3 parity bit , 7 error positions
b1 b2 b3 b4 b5 b6 b7
Digit p1 p2 m1 p3 m2 m3 m4
Error position Position number
0 0 0 0 0 0 c3 c2 c1
0 (no error) 0 0 0
1 1 0 0 0 1
1 0 0 1
2 0 1 0
2 0 0 0 1 0 3 0 1 1
4 1 0 0
3 1 0 0 1 1 5 1 0 1
6 1 1 0
4 1 0 1 0 0 7 1 1 1

5 0 0 1 0 1

6 1 0 1 1 0 C1=b1Ꚛb3Ꚛb5Ꚛb7
C2= b2Ꚛb3Ꚛb6Ꚛb7
7 0 0 1 1 1 C3= b4Ꚛb5Ꚛb6Ꚛb7
8 1 1 0 0 0
9 0 1 0 0 1
How to correct the bits
• Calculate the three check bits
• C1=b1Ꚛb3Ꚛb5Ꚛb7
• C2= b2Ꚛb3Ꚛb6Ꚛb7
• C3= b4Ꚛb5Ꚛb6Ꚛb7
• C3C2C1=000 no error
• C3C2C1 gives the error position
Construct hamming code for 0110.use even parity?
If hamming code sequence 1100110 is transmitted, due to error it is transmitted as 1110110.Locate thr position of
error using parity check and correct the sequence
Thankyou

You might also like