ham84.c
上传用户:zslianheng
上传日期:2013-04-03
资源大小:946k
文件大小:3k
源码类别:

Linux/Unix编程

开发平台:

Visual C++

  1. /*
  2. $Log: ham84.c,v $
  3. Revision 1.1.1.1  2002/07/28 05:23:27  freeman_yong
  4. lpc10 codec
  5.  * Revision 1.1  1996/08/19  22:32:07  jaf
  6.  * Initial revision
  7.  *
  8. */
  9. #ifdef P_R_O_T_O_T_Y_P_E_S
  10. extern int ham84_(integer *input, integer *output, integer *errcnt);
  11. #endif
  12. /*  -- translated by f2c (version 19951025).
  13.    You must link the resulting object file with the libraries:
  14. -lf2c -lm   (in that order)
  15. */
  16. #include "f2c.h"
  17. /* ***************************************************************** */
  18. /*  HAM84 Version 45G */
  19. /* $Log: ham84.c,v $
  20. /* Revision 1.1.1.1  2002/07/28 05:23:27  freeman_yong
  21. /* lpc10 codec
  22. /*
  23.  * Revision 1.1  1996/08/19  22:32:07  jaf
  24.  * Initial revision
  25.  * */
  26. /* Revision 1.3  1996/03/21  15:26:00  jaf */
  27. /* Put comment header in standard form. */
  28. /* Revision 1.2  1996/03/13  22:00:13  jaf */
  29. /* Comments added explaining that none of the local variables of this */
  30. /* subroutine need to be saved from one invocation to the next. */
  31. /* Revision 1.1  1996/02/07 14:47:04  jaf */
  32. /* Initial revision */
  33. /* ***************************************************************** */
  34. /*  Hamming 8,4 Decoder - can correct 1 out of seven bits */
  35. /*   and can detect up to two errors. */
  36. /* Input: */
  37. /*  INPUT  - Seven bit data word, 4 bits parameter and */
  38. /*           4 bits parity information */
  39. /* Input/Output: */
  40. /*  ERRCNT - Sums errors detected by Hamming code */
  41. /* Output: */
  42. /*  OUTPUT - 4 corrected parameter bits */
  43. /* This subroutine is entered with an eight bit word in INPUT.  The 8th */
  44. /* bit is parity and is stripped off.  The remaining 7 bits address the */
  45. /* hamming 8,4 table and the output OUTPUT from the table gives the 4 */
  46. /* bits of corrected data.  If bit 4 is set, no error was detected. */
  47. /* ERRCNT is the number of errors counted. */
  48. /* This subroutine has no local state. */
  49. /* Subroutine */ int ham84_(integer *input, integer *output, integer *errcnt)
  50. {
  51.     /* Initialized data */
  52.     static integer dactab[128] = { 16,0,0,3,0,5,14,7,0,9,14,11,14,13,30,14,0,
  53.     9,2,7,4,7,7,23,9,25,10,9,12,9,14,7,0,5,2,11,5,21,6,5,8,11,11,27,
  54.     12,5,14,11,2,1,18,2,12,5,2,7,12,9,2,11,28,12,12,15,0,3,3,19,4,13,
  55.     6,3,8,13,10,3,13,29,14,13,4,1,10,3,20,4,4,7,10,9,26,10,4,13,10,15,
  56.     8,1,6,3,6,5,22,6,24,8,8,11,8,13,6,15,1,17,2,1,4,1,6,15,8,1,10,15,
  57.     12,15,15,31 };
  58.     integer i__, j, parity;
  59. /*       Arguments */
  60. /*       Parameters/constants */
  61. /*       Local variables that need not be saved */
  62. /*  Determine parity of input word */
  63.     parity = *input & 255;
  64.     parity ^= parity / 16;
  65.     parity ^= parity / 4;
  66.     parity ^= parity / 2;
  67.     parity &= 1;
  68.     i__ = dactab[*input & 127];
  69.     *output = i__ & 15;
  70.     j = i__ & 16;
  71.     if (j != 0) {
  72. /*          No errors detected in seven bits */
  73. if (parity != 0) {
  74.     ++(*errcnt);
  75. }
  76.     } else {
  77. /*          One or two errors detected */
  78. ++(*errcnt);
  79. if (parity == 0) {
  80. /*             Two errors detected */
  81.     ++(*errcnt);
  82.     *output = -1;
  83. }
  84.     }
  85.     return 0;
  86. } /* ham84_ */