void params() {
printf("Enter the length of the Hamming code: ");
scanf("%d", &hamming_length);
printf("Enter the parity (o=even, 1=odd): ");
scanf("%d", &parity_type);
hamming = (char *) malloc (hamming_length * sizeof(char));
return;
}
/* Option #2 */
void check_hamming_code() {
/* declare local var's */
int i,j,k;
/* prompt for hamming code string */
printf("Enter the Hamming code: ");
scanf("%s",hamming);
for(i=1; i < hamming_length; i*=2) {
/* init. something in i */
int current_parity = parity_type;
for(j=i; j <= hamming_length; j+=2*i) {
/* init. something in j */
for(k=j; (k <= hamming_length) && (k < i+j); k++) {
if(k != i)
current_parity = current_parity ^ hamming[hamming_length-k];
} /* end of k loop */
} /* end of j loop */
error_bit = error_bit + (current_parity ^ (hamming[hamming_length-i]-'0'))*i;
} /* end i loop */
/* correct error bit */
printf("%d",error_bit);
return;
}
Title | # Comments | Views | Activity |
---|---|---|---|
Load and store *.pnm image file | 1 | 68 | |
How to mimic the following Windows API, GetLogicalDrives(), on Ubuntu Linux 15.10 using a series of C# Mono functions? | 12 | 104 | |
change colour of repeater control in asp.net c# | 7 | 58 | |
Acrinis True image | 2 | 18 |
Join the community of 500,000 technology professionals and ask your questions.
Connect with top rated Experts
24 Experts available now in Live!