Question
#include #include using namespace std; void printstate( bool *s) { /* This function prints out the 25 bit register*/ cout < < state: ; for
#include
#include
using namespace std;
void printstate(bool *s)
{
/* This function prints out the 25 bit register*/
cout << "state: ";
for(int i =0; i < 25;i++)
cout << s[i];
cout << endl;
}
void leftshift(bool *s)
{
/*This function shifts the 25 bit register one place to the left*/
//You do this!
}
void timestep(bool *s)
{
/* This function executes one time step of the NLFSR.
* The state variable s (which is an array of bool types of length 25)
* should be updated according to the NLFSR update rule as discussed
* in the project description.*/
//You do this!
}
void runnlfsr(bool *s, int numsteps, bool print)
{
/*This function runs the LFSR from the state s for numsteps steps*/
for(int i =0 ; i < numsteps; i++)
{
if(print)
{
cout << s[0];
}
timestep(s);
}
cout << endl;
}
#define INITIALSTATE {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}
const bool t[25] = INITIALSTATE;
void setstate(bool *s)
{/*This function makes the state equal to the initial state (defined above)*/
for(int i=0; i < 25; i++)
s[i]=t[i];
}
bool period_over(bool *s)
{/*This function returns true iff the current state is equal to the initial state*/
for(int i = 0; i < 25;i++)
{
if(t[i] != s[i])
return false;
}
return true;
}
int main()
{
bool state[25];
setstate(state);
runnlfsr(state,50,true);
setstate(state);
runnlfsr(state,(1 << 25)-1,false);
// 2**25 -1
runnlfsr(state,50,true);
return 1;
}
int main2()
{
bool state[25];
setstate(state);
timestep(state);
int i = 1;
while(!period_over(state))
{
timestep(state);
i++;
}
cout << "done in " << i << " steps" << endl;
printstate(state);
return 1;
}
note: Read the comments in each function, they are your guidance.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started