Professional Documents
Culture Documents
Practical CN
Practical CN
Practical-4
|Page
IU2041050070
Practical-5
|Page
IU2041050070
Practical-6
Bit Stuffing:
#include <stdio.h>
#include <string.h>
if (input[i] == '1') {
count++;
if (count == 5) {
output[j++] = '0';
count = 0;
}
} else {
count = 0;
}
}
output[strlen(input) + count] = '\0';
}
|Page
IU2041050070
int main() {
char input[] = "0111110101101111101";
char output[100];
bit_stuffing(input, output);
return 0;
}
|Page
IU2041050070
Practical-7
Byte Stuffing:
#include <stdio.h>
#include <string.h>
int main() {
char input[] = "\x7E\xA0\xA1\x7E";
char output[100];
|Page
IU2041050070
return 0;
}
|Page
IU2041050070
Practical-8
Parity Checking:
#include <stdio.h>
#include <string.h>
return parity;
}
int main() {
char data[] = "1101010";
int received_parity = 1; // Replace with the received parity bit
int calculated_parity = calculate_parity(data, strlen(data));
if (received_parity == calculated_parity) {
|Page
IU2041050070
return 0;
}
Practical-9
|Page
IU2041050070
return lrc;
}
|Page
IU2041050070
return vrc;
}
int is_correct = 1;
for (int i = 0; i < 8; i++) {
if (received_vrc[i] != calculated_vrc[i]) {
is_correct = 0;
break;
}
}
return is_correct;
}
|Page
IU2041050070
int main() {
char data[] = {0b10101010, 0b11001100, 0b11110000};
int received_lrc = 0b01010101;
int received_vrc[] = {0, 1, 0, 1, 0, 1, 0, 1};
printf("Data: ");
for (int i = 0; i < sizeof(data); i++) {
printf("%02X ", data[i]);
}
printf("\nReceived LRC: %02X\n", received_lrc);
printf("Is LRC Correct: %s\n", is_lrc_correct ? "Yes" : "No");
printf("Received VRC: ");
for (int i = 0; i < 8; i++) {
printf("%d ", received_vrc[i]);
}
printf("\nIs VRC Correct: %s\n", is_vrc_correct ? "Yes" : "No");
return 0;
}
|Page
IU2041050070
Practical-10
#include <stdio.h>
#include <string.h>
void crc_remainder(int *data, int data_len, int *divisor, int divisor_len, int
*remainder) {
int crc[data_len + divisor_len - 1];
|Page
IU2041050070
}
}
return 1;
}
int main() {
int data[] = {1, 0, 1, 0, 1, 1, 0};
int divisor[] = {1, 0, 0, 1}; // CRC-4 divisor
int data_with_crc[11];
int divisor_len = sizeof(divisor) / sizeof(divisor[0]);
int data_len = sizeof(data) / sizeof(data[0]);
|Page
IU2041050070
printf("Data: ");
for (int i = 0; i < data_len; i++) {
printf("%d ", data[i]);
}
printf("\nGenerated CRC: ");
for (int i = data_len; i < data_len + divisor_len - 1; i++) {
printf("%d ", data_with_crc[i]);
}
printf("\nIs CRC Correct: %s\n", is_crc_correct ? "Yes" : "No");
return 0;
}
|Page