Con Call Reminder - Protection for Asynchronous phases

Jim McGrath Jim.McGrath at quantum.com
Tue Mar 2 09:51:22 PST 1999


* From the T10 Reflector (t10 at symbios.com), posted by:
* Jim McGrath <Jim.McGrath at quantum.com>
*



> On the con call today there was a request for the encoding/decoding code
> for the proposed BCH code.
> 
> The following is the code.  I doubt we want to include this in the
> standard(!), but it should help developers in evaluating the code.
> 
> Jim
> 
> 
> 
> }
> /*******************End of (21,16,3) code listing   ******/
> /*************************************************************************
> ******/
> /******** Beginning of (21,15,4) code listing
> **********************/
> /** (21,15,4) cyclic code **
> /** total length = 21 bits, number of data bits = 15,
>    number of redundant bits = 6, minimum distance = 4
>    generator poly = <oct>0145  **/
> /** This code can be shortened to (17,11,4) code with 11 data bits and 6
>      redundant bits; distance = 4  by assigning zeros to the leading 4
> data
>      bits (out of original 15 bits) ***/   
> #include <stdio.h>
> unsigned short gen_poly = 0145;
> unsigned short degree_term = 0100;
> unsigned short table_04[4];
> unsigned short table_16[16];
> int main()
> {
> 
>   unsigned short data,edc_single,edc_double,edc_four;
>   unsigned short serial_encode();
>   unsigned short two_bit_parellel_encode();
>   unsigned short four_bit_parellel_encode();
>    short k;
>    short making_tables();
>    
>    making_tables();
>  
>   while(1)
>    {
>      printf("Enter an fifteen-bit data in <hex> format:\n");
>      scanf("%hx",&data);
>      data &= 0x7fff;
>      edc_single = serial_encode(data);
>      printf(" data = <hex>%04x, serial-encoded edc    = <hex>%02x\n",data,
>      edc_single);
>      edc_double = two_bit_parellel_encode(data);
>      printf(" data = <hex>%04x, two_bit_parellel edc  = <hex>%02x\n",data,
>      edc_double);
>       edc_four = four_bit_parellel_encode(data);
>      printf(" data = <hex>%04x, four_bit_parellel edc = <hex>%02x\n",data,
>      edc_four);
>      
>      if(data==0) break;
>    }
> 
> }
> 
> short making_tables()
> {short k;
>  
>   table_04[0] = 0;
>   table_04[1] = gen_poly;
>   table_04[2] = (gen_poly<<1);
>   if(table_04[2] & degree_term) table_04[2] ^= gen_poly;
>   table_04[3] = table_04[2] ^ table_04[1];
> 
>   table_16[0] = 0;
>   table_16[1] = table_04[1];
>   table_16[2] = table_04[2];
>   table_16[3] = table_04[3];
>   table_16[4] = table_04[2] << 1;
>   if(table_16[4] & degree_term) table_16[4] ^= gen_poly;
> 
>  for(k=1; k < 4; k++)  table_16[4+k] = table_16[4] ^ table_16[k];
>   table_16[8] = table_16[4] << 1;
>   if(table_16[8] & degree_term) table_16[8] ^= gen_poly;
>   for(k=1; k<8;k++)  table_16[8+k] = table_16[8] ^ table_16[k]; 
> 
> 
>  return(1);
>  }
> 
> unsigned short serial_encode(data)
> unsigned short data;  /** data contains at most 15 bits **/
> {
>  short k;
>  unsigned short reg;
>  
>  reg = 0;
>  for(k=14; k >= 0; k--)
>   {reg <<= 1;
>    
>  
>    if(data & (1<<k)) reg ^= degree_term;
>    if(reg & degree_term) reg ^= gen_poly;
> /***    printf(" k = %d, reg = <hex>%x\n",k,reg); ***/
>    }
>    
>    return(reg);
> 
> }
> 
> unsigned short two_bit_parellel_encode(data)
> unsigned short data;  /** data contains at most 15 bits **/
> {
>  short k;
>  unsigned short reg;
>  unsigned short index;
> 
>  reg = 0;
>  for(k=14; k >= 0; k -= 2)
>   {
>     /** left shift reg by 2 and exor with 2 bits of data at bit k and bit
> k+1 **/
>     reg = (reg<<2) ^ (((data>>k)&3)<<6);
>    
> 
>    index = (reg >> 6) & 03;
>    reg ^= table_04[index];
> 
>    }
>    
>    return(reg);
> 
> }
> unsigned short four_bit_parellel_encode(data)
> unsigned short data;  /** data contains at most 15 bits **/
> {
>  short k;
>  unsigned short reg;
>  unsigned short index;
>  reg = 0;
>  for(k=12; k >= 0; k -= 4)
>   {
>      reg = (reg<<4) ^ (((data>>k)&0xf)<<6); /** taking four bits of data
> and
>                                                  exoring them to reg **/
>   
>      index = (reg >> 6)& 0xf;
>    reg ^= table_16[index];
> 
>    
> 
>    }
>    
>    return(reg);
> 
> }
> /**********************End of (21,15,4) code listing ****/
> 
*
* For T10 Reflector information, send a message with
* 'info t10' (no quotes) in the message body to majordomo at symbios.com





More information about the T10 mailing list