22BCE3591 Assessment2
22BCE3591 Assessment2
Check Sum:
Code:
#include <stdio.h>
//Dhruv Kalpesh Jadav
//22BCE3591
if (checksum == 0) {
printf("\nData received is correct.\n");
} else {
printf("\nError detected in received data.\n");
}
}
int main() {
int n;
DHRUV KALPESH JADAV 22BCE3591
int data[n];
int dataR[n];
printf("Enter the elements of the array:\n");
for(int i = 0; i < n; i++) {
scanf("%d", &data[i]);
}
Output:
DHRUV KALPESH JADAV 22BCE3591
Hamming Code:
Code:
#include <stdio.h>
#include <math.h>
//Dhruv Kalpesh Jadav
//22BCE3591
int input[32];
int code[32];
int main() {
int n, parity_count = 0, code_length;
if (error_position == 0) {
printf("The received Data is correct.\n");
} else {
printf("Error at bit position: %d\n", error_position);
}
}
DHRUV KALPESH JADAV 22BCE3591
Output:
CRC:
Code:
#include <stdio.h>
#include <string.h>
//Dhruv Kalpesh Jadav
//22BCE3591
int n = strlen(dividend);
while (pick < n) {
if (tmp[0] == '1') {
xor1(tmp, divisor, tmp);
} else {
char allZero[pick + 1];
memset(allZero, '0', pick);
allZero[pick] = '\0';
xor1(tmp, allZero, tmp);
}
strncat(tmp, ÷nd[pick], 1);
pick++;
}
if (tmp[0] == '1') {
xor1(tmp, divisor, tmp);
} else {
char allZero[pick + 1];
memset(allZero, '0', pick);
allZero[pick] = '\0';
xor1(tmp, allZero, tmp);
}
strcpy(remainder, tmp);
}
char remainder[100];
mod2div(remainder, appended_data, key);
strcpy(encoded, data);
strcat(encoded, remainder);
int main() {
char data[100], key[100], received_data[100];
char encoded[200];
encodeData(data, key, encoded);
receiver(received_data, key);
}
DHRUV KALPESH JADAV 22BCE3591
Output: