0

I am trying to understand how change the galois LFSR code to be able to specify the output bit number as a parameter for the function mentioned below. I mean I need to return not the last bit of LFSR as output bit, but any bit of the LFSR ( for example second or third bit). I am really stuck up with this question. Can anybody give some hint how to implement that?

#include < stdint.h >
uint16_t lfsr = 0xACE1u;
unsigned period = 0;
do {
  unsigned lsb = lfsr & 1;
  /* Get lsb (i.e., the output bit - here we take the last bit but i need to take any bit the number of which is specified as an input parameter). */
  lfsr >>= 1;
  /* Shift register */
  if (lsb == 1)
  /* Only apply toggle mask if output bit is 1. */
    lfsr ^= 0xB400u;
  /* Apply toggle mask, value has 1 at bits corresponding* to taps, 0 elsewhere. */
  ++period;
} while (lfsr != 0xACE1u);
4

1 回答 1

2

如果您需要 bit k (k = 0 ..15),您可以执行以下操作:

return (lfsr >> k) & 1;

这会将寄存器k位位置向右移动并屏蔽最低有效位。

于 2015-06-22T15:14:25.913 回答