我有个程序是(64,48)码的,但不会改为(26,16)码编码: /* Function gen_ckbits() returns the first 15 check bits of a transmit */ /* codeword (codeword bits 49 to 63). Bit 15 of the returned value will */ /* be codeword bit 49, bit 1 of the returned value will be codeword bit */ /* 63, and the lsb (bit 0) should be ignored. */ /* The last bit (64) of the codeword must be derived separately, to */ /* give even parity of the whole 64-bit codeword. */ gen_ckbits() { int n,bit; unsigned int ckbits = 0; /* Clear check bits */ for(n=1;n <= 48;n++) /* 48 information bits */ { /* */ bit = getbit_tx(n); /* Get each bit in turn */ if( 1 & (bit ^ (ckbits >> 15))) /* XOR tx bit with MSB */ /* of checkbits and if */ /* the result == 1 */ ckbits ^= 0x6815; /* then XOR checkbits */ /* with 6815 Hex */ ckbits <<= 1; /* ... Shift check bit word */ /* one bit left, */ } return(ckbits ^ 0x0002); /* Return checkbits with */ /* codeword bit 63 inverted */ } /* Function getbit_tx(n) should return bit ‘n’ (1 to 48) of the transmit*/ /* codeword information field. */ getbit_tx(n) { return(/* 1 or 0 */); }
解码: /* Function calc_syndrome() returns the 16-bit ‘Syndrome’ of a received */ /* MPT1327 64-bit codeword. */ calc_syndrome() { int n,bit; int parity=0; /* Clear parity register */ int syndrome=0; /* Clear 16-bit syndrome */ for(n = 1;n <= 64;n++) /* 64-bit codeword... */ { /* */ bit = getbit_rx(n); /* Get each bit in turn;.. */ parity ^= bit; /* .. update parity */ if(n == 63) bit ^= 1; /* .. then invert bit 63 */ if(n < 64) /* .. for bits 1 to 63;.... */ { /* .. shift parity word */ syndrome <<= 1; /* one bit left. */ if( 1 & (bit ^ (syndrome >> 15))) /* .. XOR rx bit with */ /* MSB of parity word, */ /* and if result == 1 */ syndrome ^= 0x6815; /* then XOR syndrome */ /* with 6815 Hex. */ } /* */ } syndrome &= 0x7FFF; /* Finally, replace MSB of */ if(parity) /* syndrome word with the */ syndrome |= 0x8000; /* calculated parity bit */ return(syndrome); } /* Function getbit_rx(n) should return the bit ‘n’ of the received */ /* codeword; Bit ‘1’ is the first bit to be received, bit ‘64’ the last. */ getbit_rx(n) { return(/* 1 or 0 */); }
/* Function gen_ckbits() returns the first 15 check bits of a transmit */
/* codeword (codeword bits 49 to 63). Bit 15 of the returned value will */
/* be codeword bit 49, bit 1 of the returned value will be codeword bit */
/* 63, and the lsb (bit 0) should be ignored. */
/* The last bit (64) of the codeword must be derived separately, to */
/* give even parity of the whole 64-bit codeword. */
gen_ckbits()
{
int n,bit;
unsigned int ckbits = 0; /* Clear check bits */
for(n=1;n <= 48;n++) /* 48 information bits */
{ /* */
bit = getbit_tx(n); /* Get each bit in turn */
if( 1 & (bit ^ (ckbits >> 15))) /* XOR tx bit with MSB */
/* of checkbits and if */
/* the result == 1 */
ckbits ^= 0x6815; /* then XOR checkbits */
/* with 6815 Hex */
ckbits <<= 1; /* ... Shift check bit word */
/* one bit left, */
}
return(ckbits ^ 0x0002); /* Return checkbits with */
/* codeword bit 63 inverted */
}
/* Function getbit_tx(n) should return bit ‘n’ (1 to 48) of the transmit*/
/* codeword information field. */
getbit_tx(n)
{
return(/* 1 or 0 */);
}
/* Function calc_syndrome() returns the 16-bit ‘Syndrome’ of a received */
/* MPT1327 64-bit codeword. */
calc_syndrome()
{
int n,bit;
int parity=0; /* Clear parity register */
int syndrome=0; /* Clear 16-bit syndrome */
for(n = 1;n <= 64;n++) /* 64-bit codeword... */
{ /* */
bit = getbit_rx(n); /* Get each bit in turn;.. */
parity ^= bit; /* .. update parity */
if(n == 63) bit ^= 1; /* .. then invert bit 63 */
if(n < 64) /* .. for bits 1 to 63;.... */
{ /* .. shift parity word */
syndrome <<= 1; /* one bit left. */
if( 1 & (bit ^ (syndrome >> 15))) /* .. XOR rx bit with */
/* MSB of parity word, */
/* and if result == 1 */
syndrome ^= 0x6815; /* then XOR syndrome */
/* with 6815 Hex. */
} /* */
}
syndrome &= 0x7FFF; /* Finally, replace MSB of */
if(parity) /* syndrome word with the */
syndrome |= 0x8000; /* calculated parity bit */
return(syndrome);
}
/* Function getbit_rx(n) should return the bit ‘n’ of the received */
/* codeword; Bit ‘1’ is the first bit to be received, bit ‘64’ the last. */
getbit_rx(n)
{
return(/* 1 or 0 */);
}
http://www.mvista.com.cn/svu-www/index4/index4-10/index4-10-5.htm