LFSR.java
This is the syntax highlighted version of LFSR.java
from 1 Overview of
Introduction to Computer Science by
Robert Sedgewick and Kevin Wayne.
/*************************************************************************
* Compilation: javac LFSR.java
* Execution: java LFSR N
*
* Simulate a LFSR for N steps and print results.
*
* % java LFSR 54
* 110010010011110110111001011010111001100010111111010010
*
OLD
* 0100110010000001100010001011101010111100
*
*************************************************************************/
public class LFSR {
public static void main(String[] args) {
int N = Integer.parseInt(args[0]);
boolean b10 = false, b9 = true, b8 = true, b7 = false;
boolean b6 = true, b5 = false, b4 = false, b3 = false;
boolean b2 = false, b1 = true, b0 = false;
for (int i = 0; i < N; i++) {
boolean bit = b8 ^ b10;
b10 = b9; b9 = b8; b8 = b7; b7 = b6; b6 = b5;
b5 = b4; b4 = b3; b3 = b2; b2 = b1; b1 = b0;
b0 = bit;
if (bit) System.out.print(1);
else System.out.print(0);
}
System.out.println();
}
}
Last updated: Fri Aug 13 09:23:40 EDT 2004
.
Copyright © 2004, Robert Sedgewick and Kevin Wayne.