Binary, Parity, Error Detecting Codes
Binary, Parity, Error Detecting Codes
Dr. P. Chandrashekar
Professor
Dept. of ECE
1
Introduction
Binary codes
Code Conversion
2
List the course outcome / Topic outcome
3
Name of the topic: Binary addition, Subtraction, Complementary
Representation and operations
4
Binary Codes
Classification of binary codes
1. Weighted codes
2. Non-weighted codes
3. Reflective codes
4. Sequential codes
5. Alphanumeric codes
5
1. Weighted codes
Each digit position of the number represents a specific weight
Binary
BCD
• 8,4,2,1 2,4,2,1 3,3,2,1 5,2,1,1
• 5,3,1,1 5,4,2,1 6,3,1,1 7,4,2,1
• 7,4,-2,-1 8,4,-2,-1
Decimal BCD Excess-3 84-2-1 2421 5211
Number 8421
7
3. Reflective codes
A code is said to be reflective when code for 9 is complement
for the code for 0, and so is for 8 and 1 codes, 7 and 2, 6 and
3, 5 and 4.
Codes 2421, 5211, and excess-3 are reflective, whereas the
8421 code is not.
Decimal BCD Excess-3 84-2-1 2421 5211
Number 8421
9
5. Alphanumeric codes
10
6. Error detecting and correcting 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
Example:
Parity codes
Hamming codes
11
Binary Coded Decimal number system (8,4,2,1)
Decimal BCD
Binary coded decimal
0 0000
Only encodes ten digits from 0 to 9 1 0001
2 0010
BCD is a weighted code
3 0011
12
BCD (8,4,2,1)
13
BCD Addition
There are 6 illegal combinations 1010, 1011, 1100, 1101, 1110, 1111 in these
codes, they are not part of the 8421 BCD code system
If there is no carry & the sum term is not an illegal code, no correction is
needed
If there is a carry out of one group to the next group or if the sum term is an
illegal code then 610 (0110) is added to the sum term of that group & the
resulting carry is added to the next group
14
BCD Addition
• Perform decimal additions in 8421 code
(a) 25 + 13
15
BCD Subtraction using 9’s & 10’s compliment
• Perform decimal subtraction in 8421 code
16
BCD Subtraction
• Perform decimal subtraction in 8421 code
(a) 38 - 15
17
Other 4-bit BCD codes
18
2. Non-weighted codes
Not assigned with any weight to each digit position of the
number
Decimal Binary Excess-3 Gray
Excess-3 Number Code Code
Gray 0 0000 0011 0000
1 0001 0100 0001
2 0010 0101 0011
3 0011 0110 0010
4 0100 0111 0110
5 0101 1000 0111
6 0110 1001 0101
7 0111 1010 0100
8 1000 1011 1100
9 1001 1100 1101
19
Excess-3
Derived from the natural BCD code by adding 3 to each coded
Decimal BCD Excess-3
number. Number 8421 BCD + 0011
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
21
Binary to Gray codes
Convert (1011)2 to gray
22
Gray codes
23
Problems
1. Convert the following code to Gray code
1 0 1 1 0
(i) Binary (ii) BCD (iii) Excess-3 code and (iv) Gray code
24
6. Error detecting and correcting 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
Example:
Parity codes
Hamming codes
25
Parity
• A parity bit is used for the purpose of detecting errors during
transmission of binary information
• A parity bit is an extra bit included with a binary message to make
the number of 1s either odd or even
• If odd no. of 1s odd parity (1 1 1 0)
• If even no. of 1s even parity (1 0 0 1)
• Transmitted code has two parts
1. Parity bit
2. Message bits
26
Hamming Code: Generation
Message 1 0 0 1
P1 =0 P2 =0 P3 =1
P3 P2 P1
1 0 0 corresponds to decimal ‘4’. The error is in 4th bit.
P1=3,5,7:P2=3,6,7:P3=5,6,7
28
Generation of Hamming code
Message: 0 1 0 1
Bit P1 P2 M1 P3 M2 M3 M4
designation
Bit Position 1 2 3 4 5 6 7
Binary 001 010 011 100 101 110 111
Position
Message Bits 0 1 0 1
Parity Bits 0 1 0
29
Error Detection & Correction
I. Detection of whether received code is correct or not
0 0 1 0 0 0 1
30
Procedure
The Hamming Code received : 0 0 1 0 0 0 1
Bit P1 P2 M1 P3 M2 M3 M4
designation
Bit Position 1 2 3 4 5 6 7
Binary 001 010 011 100 101 110 111
Position
Message Bits 0 0 1 0 0 0 1
Parity Bits
31
Procedure
The Hamming Code received : 0 0 1 0 0 0 1
Parity bits: P1= 0 P2=0 P3=1
P1 P2 P3 = 0 0 1 corresponds to decimal ‘4’. The error is in
4th bit.
Bit P1 P2 M1 P3 M2 M3 M4
designation
Bit Position 1 2 3 4 5 6 7
Binary 001 010 011 100 101 110 111
Position
Message Bits 0 0 1 0 0 0 1
Parity Bits 0 0 1
Correct Message : 0 0 1 1 0 0 1
32
12 bit Hamming code
Message: 0 1 0 1 0 0 0 1
Bit P1 P2 M1 P3 M2 M3 M4 P5 M5 M6 M7 M8
designation
Bit Position 1 2 3 4 5 6 7 8 9 10 11 12
Message
Bits
P1=3,5,7,9,11
P2=3,6,7,10,11
P4=5,6,7,12
P8=9,10,11,12
33