def calc_syndrome(codeword, n):
 sym = 0
 for i in range(1, n):
  if codeword[i]:
   sym ^= i
 extra_parity = calc_parity_vector(codeword)
 if (extra_parity == codeword[0]):
  if (sym == 0):
   return (0, sym)
  else:
   return (2, sym)
 else:
  if (sym >= n):
   pass
  else:
   codeword[sym] ^= 1
  return (1, sym)

def calc_syndrome ( codeword , n ) : sym = 0 for i in range ( 1 , n ) : if codeword [ i ] : sym ^= i extra_parity = calc_parity_vector ( codeword ) if ( extra_parity == codeword [ 0 ] ) : if ( sym == 0 ) : return ( 0 , sym ) else : return ( 2 , sym ) else : if ( sym >= n ) : pass else : codeword [ sym ] ^= 1 return ( 1 , sym )
calculate syndrome and correct codeword if possible .