mirror of
https://github.com/aicodix/code.git
synced 2026-04-27 14:30:36 +00:00
35 lines
489 B
C++
35 lines
489 B
C++
/*
|
|
Maximum length sequence
|
|
|
|
Copyright 2020 Ahmet Inan <inan@aicodix.de>
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
namespace CODE {
|
|
|
|
class MLS
|
|
{
|
|
static int hibit(unsigned n)
|
|
{
|
|
n |= n >> 1;
|
|
n |= n >> 2;
|
|
n |= n >> 4;
|
|
n |= n >> 8;
|
|
n |= n >> 16;
|
|
return n ^ (n >> 1);
|
|
}
|
|
int poly, test, reg;
|
|
public:
|
|
MLS(int poly = 0b100000000000000001001, int reg = 1) : poly(poly), test(hibit(poly)>>1), reg(reg) {}
|
|
bool operator()()
|
|
{
|
|
bool fb = reg & test;
|
|
reg <<= 1;
|
|
reg ^= fb * poly;
|
|
return fb;
|
|
}
|
|
};
|
|
|
|
}
|
|
|