From 96fe7c0f7e93f646408d6147905e694e1216dae7 Mon Sep 17 00:00:00 2001 From: Kshitij Date: Wed, 9 Oct 2024 20:27:24 +0530 Subject: [PATCH] Removed A4 & C11 from testing branch. --- Codes/Code-A4 (Hamming Code).cpp | 103 ------------------------------- Codes/Code-C11.py | 34 ---------- 2 files changed, 137 deletions(-) delete mode 100644 Codes/Code-A4 (Hamming Code).cpp delete mode 100644 Codes/Code-C11.py diff --git a/Codes/Code-A4 (Hamming Code).cpp b/Codes/Code-A4 (Hamming Code).cpp deleted file mode 100644 index 30ae775..0000000 --- a/Codes/Code-A4 (Hamming Code).cpp +++ /dev/null @@ -1,103 +0,0 @@ -#include -#include -#include -using namespace std; - -// Function to calculate the number of parity bits needed -int calculateParityBits(int dataBits) { - int parityBits = 0; - while (pow(2, parityBits) < dataBits + parityBits + 1) { - parityBits++; - } - return parityBits; -} - -// Function to encode the data using Hamming code -vector encodeData(vector data) { - int dataBits = data.size(); - int parityBits = calculateParityBits(dataBits); - vector encoded(dataBits + parityBits, 0); - - // Set the data bits - int j = 0; - for (int i = 0; i < encoded.size(); i++) { - if (i + 1 == pow(2, j)) { - j++; - } else { - encoded[i] = data[i - j]; - } - } - - // Calculate and set the parity bits - for (int i = 0; i < parityBits; i++) { - int parityBit = pow(2, i); - int sum = 0; - for (int j = parityBit - 1; j < encoded.size(); j += 2 * parityBit) { - for (int k = 0; k < parityBit; k++) { - if (j + k < encoded.size()) { - sum += encoded[j + k]; - } - } - } - encoded[parityBit - 1] = sum % 2; - } - - return encoded; -} - -// Function to check for errors in the encoded data -int checkForErrors(vector encoded) { - int parityBits = calculateParityBits(encoded.size() - calculateParityBits(encoded.size())); - int errorPosition = 0; - - for (int i = 0; i < parityBits; i++) { - int parityBit = pow(2, i); - int sum = 0; - for (int j = parityBit - 1; j < encoded.size(); j += 2 * parityBit) { - for (int k = 0; k < parityBit; k++) { - if (j + k < encoded.size()) { - sum += encoded[j + k]; - } - } - } - errorPosition += (sum % 2) * parityBit; - } - - return errorPosition; -} - -int main() { - int dataBits; - cout<<"Enter the number of data bits:\t"; - cin >> dataBits; - - vector data(dataBits); - cout<> data[i]; - } - - vector encoded = encodeData(data); - cout< receivedEncoded(encoded.size()); - for (int i = 0; i < encoded.size(); i++) { - cin >> receivedEncoded[i]; - } - - int errorPosition = checkForErrors(receivedEncoded); - if (errorPosition == 0) { - cout<<"No errors detected."<