Arif DC Lab-Report-02
Arif DC Lab-Report-02
Lab Experiment Name: Implement an even/odd parity checker where user input will be the bit
stream.
Student Details
Name ID
[For Teachers use only: Don’t Write Anything inside this box]
Signature:.....................
1.TITLE OF THE LAB EXPERIMENT:
Implement an even/odd parity checker where user input will be the bit stream.
2.OBJECTIVES:
To attain knowledge on the parity checking and how it works.
To attain knowledge on the even/odd parity check and how it works.
To implement parity checker and even/odd parity error detection algorithms.
3.IMPLEMENTATION:
Parity bit means nothing but an additional bit added to the data at the transmitter before transmitting the
data. Before adding the parity bit, number of 1’s or zeros is calculated in the data. Based on this
calculation of data an extra bit is added to the actual information / data. The addition of parity bit to the
data will result in the change of data string size.
This means if we have an 8 bit data, then after adding a parity bit to the data binary string it will
become a 9 bit binary data string.
Parity check is also called as “Vertical Redundancy Check (VRC)”.
There is two types of parity bits in error detection, they are 1. Even parity and 2. Odd parity Even
Parity If the data has even number of 1’s, the parity bit is 0. Ex: data is 10000001 -> parity bit 0 and
Odd number of 1’s, the parity bit is 1 Ex: data is 10010001 -> parity bit 1.
Odd Parity If the data has odd number of 1’s, the parity bit is 0. Ex: data is 10011101 -> parity bit
0 and Even number of 1’s, the parity bit is 1. Ex: data is 10010101 -> parity bit 1
4.Code:
#include <iostream>
#include <string>
char getParity(std::string bitStream, bool isEvenParity) {
int countOnes = 0; for
(char bit : bitStream) { if
(bit == '1') {
countOnes++;
}
}
if (isEvenParity) {
return (countOnes % 2 == 0) ? '0' : '1';
} else { return (countOnes % 2 == 0) ? '1'
: '0';
}
}
return 0;
}
5 . Output:
6.ANALYSISAND DISCUSSION:
In digital communication system errors are transferred from one communication system to another,
along with the data. If these errors are not detected and corrected, data will be lost . For effective
communication, data should be transferred with high accuracy .This can be achieved by first detecting
the errors and then correcting them.
Error detection is the process of detecting the errors that are present in the data transmitted from
transmitter to receiver, in a communication system. We use some redundancy codes to detect these
errors, by adding to the data while it is transmitted from source (transmitter). These codes are called
"Error detecting codes". Types of error detection we will study today:
• Parity Checking
1. Even parity
2. Odd Parity
7.SUMMARY:
The program takes a bit stream as input from the user.It counts the number of '1's in the bit stream to
determine the parity bit.The overall parity is determined based on whether the number of '1's is even
or odd.The original bit stream, parity bit, and overall parity are displayed to the user.The program
successfully implements an even/odd parity checker for a given bit stream.It accurately calculates the
parity bit and determines the overall parity.The implementation is simple and straightforward, making
it easy to understand and use.