Content deleted Content added
John Comeau (talk | contribs) →Code sample for the binary field in Java: changed variables to match pseudocode [again] |
revert last 4; style change; ints better than char; WP is about algorithms rather than programming |
||
Line 141:
The following is the Berlekamp–Massey algorithm specialized for the typical binary [[finite field]] F<sub>2</sub> (also written GF(2)). The field elements are '0' and '1'. The field operations '+' and '−' are identical and are equivalent to the 'exclusive or' operation, XOR. The multiplication operator '*' becomes the logical AND operation. The division operator reduces to the identity operation (i.e., field division is only defined for dividing by 1, and x/1 = x).
#Let <math>
#Initialise two arrays <math>
#[[Assignment (computer science)|assign]] <math>L \leftarrow 0, m \leftarrow -1</math>.
#'''For''' <math>
#*Let <math>d</math> be <math>
#*'''if''' <math>d = 0</math>, '''then''' <math>
#*'''else''':
#** Let <math>
#** Set <math>
#** If <math>L \le \frac{
At the end of the algorithm, <math>L</math> is the length of the minimal LFSR for the stream, and we have <math>
==Code sample for the binary field in Java==
Line 159:
<source lang="java">
int
for (int n = 0; n < N; n++) {
int d =
for (int i =
d ^= }▼
if (d == 1) {
System.arraycopy(
}▼
l = n + 1 - l;
m = n;
System.arraycopy(
}
}
}
return
▲ for (int i = 0; i < array.length(); i++) {
▲ }
▲ }
▲ public static void main(String[] args) {
▲ if (args.length > 0) {
▲ } else {
}
</source>
|