-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgolay.c
40 lines (33 loc) · 890 Bytes
/
golay.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/*
AN EFFICIENT GOLAY CODEC FOR
MIL-STD-188-141A AND FED-STD-1045
ERIC E. JOHNSON
NMSU-ECE-91-001 FEBRUARY 1991
New Mexico State University
Dept. 3-O
Las Cruces, NM 88003-0001
*/
#include "encode_table.h" /* P matrix "int enc[4096] = { ... }" */
#define myencode(x) (((long)x<<12)|enc[x])
#include "errwt.h" /* error weight matrix "int wt[4096] = { ... }" */
#include "errpat.h"/* error pattern matrix "int e[4096] = { ... }" */
#include <stdio.h>
#define ERROR_DETECTED -1
/******************** GOLAY DECODER MODULE *********************/
int errwt(long w)
{
register int i;
i = (myencode(w>>12) ^ w) & 07777;
return (wt[i]);
}
long Gdecode(long w, long power) /* decode one 24-bit Golay word */
{
register int i;
if (errwt(w) > power) return (ERROR_DETECTED);
i = (myencode(w>>12) ^ w) & 07777;
return (w>>12 ^ e[i]);
}
long Gencode(long w)
{
return myencode(w);
}