Content deleted Content added
GreenC bot (talk | contribs) |
John Comeau (talk | contribs) →Code sample for the binary field in Java: made variables match closer to pseudocode; using char[] arrays instead of int[] for easier conversion to and from strings; made output something more usable than simply length of polynomial ~~~~ |
||
Line 159:
<source lang="java">
public class BerlekampMassey {
public static int runTest(int[] array) {▼
public static String findPolynomial(char[] s) {
final int N = array.length;▼
final int
for (int
int
for (int
for (int i = 0; i <= l; i++) {▼
d ^= c[i] * array[n - i];▼
}
if (d == 1) {
System.arraycopy(c, 0, t, 0,
int
for (int
c[
}
} }
public static String findPolynomial(String array) {
char[] charArray = array.toCharArray();
charArray[i] -= '0';
}
return findPolynomial(charArray);
}
public static String stringify(char[] array, int length) {
// convert `length` chars of array to string, and reverse it
char[] output = new char[length];
}
return String.valueOf(output);
}
if (args.length > 0) {
System.out.println(findPolynomial(args[0]));
} else {
System.err.println("Example: java BerlekampMassey 100110101111000");
}
▲ return l;
}
}
</source>
|