-
Notifications
You must be signed in to change notification settings - Fork 0
/
golay.java
65 lines (62 loc) · 1.55 KB
/
golay.java
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import java.io.*;
class Main
{
public int hammingDistance(int a, int b)
{
int xor = a ^ b;
int count = 0;
while(xor != 0)
{
if((xor & 1) == 1)
{
count++;
}
xor = xor >>> 1;
}
return count;
}
public int[] golay()
{
int[] codeWords = new int[4096];
codeWords[0] = 0; // set first code word at 0000 0000
int count = 1;
int index;
int codeIndex;
boolean isCodeWord = false;
for(index = 0; index <= 0xFFFFFF; index++)
{
for(codeIndex = 0; codeIndex < 4096; codeIndex++)
{
if(hammingDistance(index, codeWords[codeIndex]) < 8)
{
isCodeWord = false;
break;
}
isCodeWord = true;
}
if(isCodeWord)
{
codeWords[count++] = index;
isCodeWord = false;
}
}
return codeWords;
}
public static void main(String[] args)
{
try {
PrintWriter writer = new PrintWriter("C:/Users/IrateGod/Documents/GolayOutput.txt", "UTF-8");
Main m = new Main();
int[] array = m.golay();
for(int index = 0; index < 4096; index++)
{
writer.println(index + ": " + array[index] + " (" + Integer.toBinaryString(array[index]) + ")");
}
writer.close();
}
catch(Exception e)
{
// ignore
}
}
}