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

Assignment 4

The document presents an assignment for a Data Communication & Networking Lab, focusing on error detection and correction using Hamming Codes or CRC for 7/8 bits ASCII codes. It includes a C++ program that allows users to generate Hamming codes or detect errors in received data, with user prompts for input and error messages based on the results. The assignment also mentions demonstrating packet traces using the Wireshark Packet Analyzer Tool.

Uploaded by

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

Assignment 4

The document presents an assignment for a Data Communication & Networking Lab, focusing on error detection and correction using Hamming Codes or CRC for 7/8 bits ASCII codes. It includes a C++ program that allows users to generate Hamming codes or detect errors in received data, with user prompts for input and error messages based on the results. The assignment also mentions demonstrating packet traces using the Wireshark Packet Analyzer Tool.

Uploaded by

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

Name: Harshita Yogesh Gandhi

Div: SY B Comp
Roll no.:13
Sub: Data Communication & Networking Lab

Assignment 4

Problem statement: Write a program for error detection and correction for 7/8 bits ASCII codes
using Hamming Codes or CRC. Demonstrate the packets captured traces using Wireshark
Packet Analyzer Tool for peer to peer mode.

Code:

#include <iostream> using


namespace std;

int main()
{ int n = 7;
int arr[n]; int
p1, p2, p4; int
choice;

cout << "Choose an option:\n1. Generate Hamming Code\n2. Detect Error in Received
Data\nEnter your choice: "; cin >> choice;

switch (choice) {
case 1:
// Encoding Hamming Code cout <<
"Enter the data bits (D3, D5, D6, D7): "; cin >>
arr[2] >> arr[4] >> arr[5] >> arr[6];

// Calculate parity bits


arr[0] = (arr[2] ^ arr[4] ^ arr[6]);
arr[1] = (arr[2] ^ arr[5] ^ arr[6]);
arr[3] = (arr[4] ^ arr[5] ^ arr[6]);

cout << "Hamming Code: ";


for (int i = 0; i < n; i++) {
cout << arr[i] << " ";
}
cout << endl;
break;
case
2:
// Error Detection cout <<
"Enter the received data bits: "; for (int
i = 0; i < n; i++) { cin >> arr[i];
}

// Recalculate parity bits


p1 = (arr[2] ^ arr[4] ^ arr[6]);
p2 = (arr[2] ^ arr[5] ^ arr[6]);
p4 = (arr[4] ^ arr[5] ^ arr[6]);

// Error detection and correction if (arr[0] ==


p1 && arr[1] == p2 && arr[3] == p4) { cout <<
"Received data is correct." << endl; } else if
(arr[0] != p1 && arr[1] != p2) { cout << "Error
detected at D3." << endl; } else if (arr[0] != p1 &&
arr[3] != p4) { cout << "Error detected at D5." <<
endl; } else if (arr[1] != p2 && arr[3] != p4) {
cout << "Error detected at D6." << endl;
} else if (arr[0] != p1 && arr[1] != p2 && arr[3] != p4) {
cout << "Error detected at D7." << endl;
}
break;

default:
cout << "Invalid choice!" << endl;
break;
}

return 0;
}

You might also like