LFSR Simulator
Simulate a Linear Feedback Shift Register using a custom binary seed and XOR tap positions. Generate register states step by step, inspect feedback and output bits, and detect when the LFSR sequence repeats.
| Step | State | Output | Feedback | Next State |
|---|---|---|---|---|
| Run the simulator to generate states. | ||||
What Is an LFSR?
A Linear Feedback Shift Register, or LFSR, is a shift register in which the next input bit is calculated from selected bits of the current register state. The selected bits are commonly called taps, and their values are combined using XOR.
After the feedback bit is calculated, the register shifts by one position and the feedback bit enters the register. Repeating this process produces a deterministic binary sequence.
Seed = 0001
Taps = 4,3
Direction = Right
Feedback = XOR of selected tap bits
Next state = feedback bit + shifted register
How to Use the LFSR Simulator
Enter a Seed
Enter the starting register state as a binary value. For example, 0001 creates a four-bit LFSR.
Choose Tap Positions
Enter the register positions whose bits should be XORed to produce the feedback bit.
Select Shift Direction
Choose whether the register moves toward the right or toward the left after each feedback calculation.
Generate the Sequence
Choose the number of transitions and run the simulator to inspect every state.
How LFSR Feedback Works
The feedback bit in this simulator is the XOR of the selected tap bits in the current register state.
1 and 0
Feedback:
1 XOR 0 = 1
If more than two taps are selected, XOR is applied successively across all selected bits.
Right-Shift LFSR
In right-shift mode, the rightmost bit is treated as the output bit. After calculating the feedback bit, the register shifts right and the feedback bit enters on the left.
abcd
Output:
d
Feedback:
f
Next state:
fabc
Left-Shift LFSR
In left-shift mode, the leftmost register bit is treated as the output. The register shifts left and the calculated feedback bit enters on the right.
abcd
Output:
a
Feedback:
f
Next state:
bcdf
LFSR Period and Cycle Length
Because an LFSR contains a finite number of states and evolves deterministically, it eventually enters a repeated state. Once a state repeats, the following sequence also repeats.
For an n-bit register, there are 2^n possible binary states. In the common XOR LFSR configuration, the all-zero state normally remains trapped at zero, so a maximal-length nonzero LFSR can have a period of:
For example, a four-bit maximal-length LFSR can have a period of 15 states.
Why the Tap Positions Matter
Not every set of taps produces a maximal-length sequence. Different feedback configurations can generate different cycle lengths even when the register width and seed are identical.
Maximal-length LFSRs are associated with primitive feedback polynomials over GF(2). When a suitable primitive configuration is used, every nonzero state can occur exactly once before the sequence repeats.
What Is the All-Zero LFSR State?
For the XOR feedback model used here, an all-zero register produces zero at every tapped position. XORing those zeros produces another zero, so the register remains in the zero state indefinitely.
↓ 0000
↓ 0000
↓ 0000
For this reason, a nonzero seed is normally used when generating conventional LFSR sequences.
LFSR Applications
Pseudorandom Sequences
LFSRs can efficiently generate deterministic bit sequences that have useful pseudorandom-like properties.
Digital Communications
Feedback shift registers are used in scrambling, test patterns and sequence-generation systems.
Hardware Testing
LFSR sequences can be used to generate test patterns for digital circuits and built-in self-test systems.
CRC Concepts
Shift-register feedback structures are closely related to polynomial arithmetic used in cyclic redundancy checking.
LFSR vs Random Number Generator
An LFSR is deterministic. If you start with the same seed, taps and shift convention, it produces exactly the same sequence again.
This makes an LFSR useful for reproducible sequence generation, but a basic LFSR should not be treated as a cryptographically secure random-number generator.
Important LFSR Simulation Notes
For right shift, the rightmost bit is displayed as the output bit and the feedback bit enters on the left.
For left shift, the leftmost bit is displayed as the output bit and the feedback bit enters on the right.
The feedback bit is calculated by XORing the selected tap positions before the register shifts.
Different LFSR references may use different tap numbering, polynomial notation, shift direction or feedback conventions. Always compare conventions when reproducing a published LFSR sequence.
An all-zero seed locks a conventional XOR LFSR in the zero state.