0% found this document useful (0 votes)
33 views4 pages

Arif DC Lab-Report-02

Uploaded by

Emran Al Arif
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)
33 views4 pages

Arif DC Lab-Report-02

Uploaded by

Emran Al Arif
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/ 4

Green University of Bangladesh

Department of Computer Science and Engineering (CSE)


Faculty of Sciences and Engineering
Semester: (Spring, Year:2024), B.Sc. in CSE (Day)

LAB REPORT NO -02


Course Title: Data Communication lab Course
Code: CSE-308 Section: 221-D4

Lab Experiment Name: Implement an even/odd parity checker where user input will be the bit
stream.

Student Details

Name ID

1. Md Arif Billah 221002520

Submission Date : 03-04-2024


CourseTeacher’s Name : Sakhaouth Hossan

[For Teachers use only: Don’t Write Anything inside this box]

Lab Report Status Marks: …………………………………

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

Algorithm for Even Parity Checking:

Here is a basic algorithm for even/odd parity checking:

1. Input: Receive a bit stream as input.


2. Count Ones: Iterate through the bit stream and count the number of ones.
3. Calculate Parity: If the number of ones is even and the parity is even, the parity bit should be 0. If
the number of ones is odd and the parity is odd, the parity bit should be 0. Otherwise, the parity
bit should be 1.
4. Output: Output the calculated parity bit.

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';
}
}

int main() { std::string


bitStream;
std::cout << "Enter the bit stream: ";
std::cin >> bitStream;

char parityBit = getParity(bitStream, true);


std::cout << "Parity bit: " << parityBit << std::endl;

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.

You might also like