23 #ifndef INCLUDED_DIGITAL_LFSR_H
24 #define INCLUDED_DIGITAL_LFSR_H
93 uint32_t d_shift_register;
96 uint32_t d_shift_register_length;
101 uint32_t r = x - ((x >> 1) & 033333333333)
102 - ((x >> 2) & 011111111111);
103 return ((r + (r >> 3)) & 030707070707) % 63;
107 lfsr(uint32_t
mask, uint32_t seed, uint32_t reg_len)
108 : d_shift_register(seed),
111 d_shift_register_length(reg_len)
114 throw std::invalid_argument(
"reg_len must be <= 31");
119 unsigned char output = d_shift_register & 1;
120 unsigned char newbit = popCount( d_shift_register & d_mask )%2;
121 d_shift_register = ((d_shift_register>>1) | (newbit<<d_shift_register_length));
127 unsigned char output = d_shift_register & 1;
128 unsigned char newbit = (popCount( d_shift_register & d_mask )%2)^(input & 1);
129 d_shift_register = ((d_shift_register>>1) | (newbit<<d_shift_register_length));
135 unsigned char output = (popCount( d_shift_register & d_mask )%2)^(input & 1);
136 unsigned char newbit = input & 1;
137 d_shift_register = ((d_shift_register>>1) | (newbit<<d_shift_register_length));
144 void reset() { d_shift_register = d_seed; }
152 for(
int i=0; i<num; i++) {
157 int mask()
const {
return d_mask; }
unsigned char next_bit_descramble(unsigned char input)
Definition: lfsr.h:133
unsigned char next_bit_scramble(unsigned char input)
Definition: lfsr.h:125
unsigned char next_bit()
Definition: lfsr.h:117
Include this header to use the message passing features.
Definition: logger.h:131
void pre_shift(int num)
Definition: lfsr.h:150
lfsr(uint32_t mask, uint32_t seed, uint32_t reg_len)
Definition: lfsr.h:107
void reset()
Definition: lfsr.h:144
Fibonacci Linear Feedback Shift Register using specified polynomial mask.
Definition: lfsr.h:90
int mask() const
Definition: lfsr.h:157