The revolutionary project management tool is here! Plan visually with a single glance and make sure your projects get done.
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;
}