Error Detection Technique in Networking

Most Simple C++ Program for Parity-Bit & Vertical and Longitudinal Redundancy Check

Error detection technique to detect errors in a received data block or frame by the receiver.

Saheel Sapovadia

--

unsplash

This started as an assignment of my DCN(Data and Communication Networks) lab to write a program(in C++) to add parity bit to carry out VRC and LRC on data stored in a text file in binary format. It was something real which made it kind of interesting for me, hence I thought of sharing it with you guys.

When a frame is transmitted from a transmitter to the receiver, there are two possibilities, either the frame is received without error or its received with error (bad frame).

  • Error detection techniques help in detecting errors in a received block or frame by the receiver.
  • Once the error is detected, receiver informs the transmitter to re-transmit the same frame again.
  • Error detection can be made possible by adding redundant bits in each frame during transmission. Based on all the bits in the frame (i.e. data + error check bits), receiver is capable of detecting errors in the frame.

Parity check or Vertical Redundancy Check (VRC) method

The parity bit can be set to 0 and 1 depending on the type of the parity required.

  • For even parity, this bit is set to 1 or 0 such that the no. of “1 bits” in the entire word is even. Shown in fig. (a).
  • For odd parity, this bit is set to 1 or 0 such that the no. of “1 bits” in the entire word is odd. Shown in fig. (b).

Here is how I combined every part to get the results -

As we are dealing with some sort of data-storage(Text file in my case), we must know the arrangement and organization of the data in it. It would help us create the link to our local variables upon which the algorithm or the operation would be executed.

The basic steps into which I have divided the whole program are-

  1. Extraction of data
  2. Processing the data
  3. Output the data after Filtering

Extraction of data

The getline() function on top of a while loop extracts all the data line-wise and stores it in the local data array val[].

Processing the data

Converting each unit of data into an integer and calculating the result(obj : res) according to our requirements i.e. either vertically or horizontally.

Output the data after Filtering

Using the most basic computer filtering mechanism if-else, filter out the processed data of the “res” object. Either print the temporary result or adjust any variable.

SOME REAL CODE NOW

Data File for VRC -

0100110
1110001
1100101
0000000
//Each line contains one set, called as a Frame.

C++ Code-

Longitudinal Redundancy Check

In this method Block of bits organized in tables e.g rows and columns and then the parity bit for each column is calculated. The set of this parity bit is also send along with the original data. From this block of parity we can check the redundancy.

Data File for LRC-

01001101
11100011
11001011
00000001
//Each line contains one set, called as a Frame.

C++ Code-

As I was the one who created the program and also the data file, I took the liberty to arrange the data_array line-wise to make things a little straightforward and easy but with some string handling you can modify the code according to your requirements.

Feel free to check out the link to my GitHub repository where I have uploaded all the necessary files -

https://github.com/saheelsapovadia/Parity-Bit-VRC-LRC

--

--

Saheel Sapovadia

I spend hours on learning new tools, so that you don’t have to. #techSavvyTeen