While exploring how to generate maximum period forward and reverse sequences using an LFSR, I ran into some confusion regarding the definition of a GF(2) primitive polynomial.
When I chose a primitive GF(2) polynomial from this table, all polynomials have the x^0 term set to 1 and everything works as expected (see below).
#include <cstdio>
#include <cstdint>
uint8_t rev (uint8_t xi)
{
uint8_t xo ;
for (auto n = 8 ; n ; -- n)
{
xo = xo << 1 | xi & 1 ;
xi >>= 1 ;
}
return xo ;
}
int main (void)
{
uint8_t const POLY_F = 0x85 ; // x^8 + x^7 + x^2 + 1 : Normal
uint8_t const POLY_R = 0x43 ; // x^8 + x^6 + x + 1 : Reversed
uint8_t lfsr = 0xFF ;
for (auto n = 1 ; n <= 5 ; ++ n) // 1 -> FF
{ // 2 -> 7B
printf ("%u -> %02X\n" , n , lfsr) ; // 3 -> F6
// 4 -> 69
lfsr = - (lfsr >> 7) & POLY_F ^ lfsr << 1 ; // 5 -> D2
}
printf ("\n") ;
for (auto n = 5 ; n >= 1 ; -- n) // 5 -> D2
{ // 4 -> 69
lfsr = rev (lfsr) ; // 3 -> F6
// 2 -> 7B
lfsr = - (lfsr >> 7) & POLY_R ^ lfsr << 1 ; // 1 -> FF
lfsr = rev (lfsr) ;
printf ("%u -> %02X\n" , n ,lfsr) ;
}
}
When I generate a maximal length GF(2) polynomial using this program, it sometimes outputs a polynomial with the x^0 term set to 0.
I cannot figure out how to reverse the sequence when the x^0 term is 0.
Is a “maximal length” polynomial the same thing as a “primitive polynomial”?
Can a primitive polynomial have the x^0 term set to 0?
Is it possible to reverse a sequence if the x^0 term is 0?
Code has at least these problems:
Uninitialized value
The first time
xo << 1 | xi & 1 ;
is executed,xo
is not initialize nor assigned.Instead:
Language?
Post is tagged C yet uses
#include <cstdio>
. Best to use a C compiler for C code.