Write a new program using your LFSR function from the first problem. Start from state 0x00000001, then run a loop counting all the possible states in the LFSR before it cycles back to 0x00000001. This is shown by the following pseudocode:   count = 0; initial = state = 0x00000001; do {     state = LFSR(state);     count++; while (state != initial); print count;

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter5: Repetition Statements
Section5.6: Nested Loops
Problem 2E
icon
Related questions
Question

Write a new program using your LFSR function from the first problem. Start from state 0x00000001, then run a loop counting all the possible states in the LFSR before it cycles back to 0x00000001. This is shown by the following pseudocode:

 

count = 0;

initial = state = 0x00000001;

do {

    state = LFSR(state);

    count++;

while (state != initial);

print count;

 

Verify that the number of states is (2^15) - 1 = 32767 . Your program should complete within 30 seconds. If it takes longer then you likely have entered an infinite loop.

Expert Solution
Step 1

Answer:

Here's a Python program that uses the LFSR function from the first problem and counts the number of possible states before the LFSR cycles back to 0x00000001:

def LFSR(state):
    mask = 0x80000001
    feedback = ((state & 1) ^ ((state >> 15) & 1)) << 31
    state = (state >> 1) & 0x7FFFFFFF
    state = state | feedback
    state = state & mask
    return state

count = 0
initial = state = 0x00000001

while state != initial or count == 0:
    state = LFSR(state)
    count += 1

print(count)

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Random Class and its operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning