我试图了解如何更改galois代码,以便能够将输出位数指定为下面提到的函数的参数。我的意思是,我不需要返回LFSR的最后一位作为输出位,而是返回LFSR的任何一点(例如第二位或第三位)。我真的很难回答这个问题。有人能给出一些如何实现的提示吗?
#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);发布于 2015-06-22 15:14:25
如果需要bit k (k = 0 ..15),可以执行以下操作:
return (lfsr >> k) & 1;这会将寄存器k位位置移到右边,并隐藏最不重要的位。
https://stackoverflow.com/questions/30983389
复制相似问题