#include #include #define X22 0x00400000 /* vector representation of X^{22} */ #define X11 0x00000800 /* vector representation of X^{11} */ #define MASK12 0xfffff800 /* auxiliary vector for testing */ #define GENPOL 0x00000c75 /* generator polinomial, g(x) */ long get_syndrome(long pattern) { /* * Compute the syndrome corresponding to the given pattern, i.e., the * remainder after dividing the pattern (when considering it as the vector * representation of a polynomial) by the generator polynomial, GENPOL. * In the program this pattern has several meanings: (1) pattern = infomation * bits, when constructing the encoding table; (2) pattern = error pattern, * when constructing the decoding table; and (3) pattern = received vector, to * obtain its syndrome in decoding. */ long aux = X22, aux2; if (pattern >= X11) { while (pattern & MASK12) { while (!(aux & pattern)) aux = aux >> 1; pattern ^= (aux/X11) * GENPOL; } } return(pattern); } void main (void) { unsigned long code; printf("Enter the 23-bit codeword in hexadecimal format: "); scanf("%lx", &code); code = ((code & 0xfff) << 11) | (code >> 12); printf("The syndrome is %0lx\n", get_syndrome(code)); }