Quantcast
Viewing all articles
Browse latest Browse all 3

Answer by olegarch for Linear Feedback Shift Register efficiency

Try this:

public int DoShift()
{
    int newBit = 1 << (length - 1); // you can save it as class member
    int result = Contents & 1;
    int feedback = Contents & tapSequence;
    Contents >>= 1;
    while(feedback != 0) {
      feedback &= feedback - 1;
      Contents ^= newBit;
    }
    return result;
}

In addition, exist more efficient approach, named "reversed LSFR". It's idea - apply tapSequence to whole register just once, if result is 1.

See example: https://en.wikipedia.org/wiki/Linear_feedback_shift_register


Viewing all articles
Browse latest Browse all 3

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>