title: Galois LFSR explanation of code
body: <p>I am trying to understand how the galois LFSR code works. On the wikipedia page there is a figure with an example. There is a C snippet code.</p>
  
  <pre><code>#include &lt;stdint.h&gt;
  uint16_t lfsr = 0xACE1u;
  unsigned period = 0;
  
  do {
  unsigned lsb = lfsr &amp; 1;  /* Get lsb (i.e., the output bit). */
  lfsr &gt;&gt;= 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);
  </code></pre>
  
  <p>I am unable to understand figure given on wikipedia and correlate with the code. what is the toggle mask doing? Can anybody explain as to how the operation is working with example bit sequence and it's shifted versions. I am not aware of fields and am not understanding code. I checked online but couldnot find any good explanations of the algorithm without going into the fields terminology. Kindly help.</p>