title: Bit hacking and modulo operation
body: <p>While reading this: <a href="http://graphics.stanford.edu/~seander/bithacks.html#ReverseByteWith64BitsDiv" rel="noreferrer">http://graphics.stanford.edu/~seander/bithacks.html#ReverseByteWith64BitsDiv</a></p>
  
  <p>I came to the phrase:</p>
  
  <blockquote>
    <p>The last step, which involves modulus division by 2^10 - 1, has the
    effect of merging together each set of 10 bits (from positions 0-9,
    10-19, 20-29, ...) in the 64-bit value.</p>
  </blockquote>
  
  <p>(it is about reversing the bits in a number)...</p>
  
  <p>so I did some calculations:</p>
  
  <pre><code>reverted = (input * 0x0202020202ULL &amp; 0x010884422010ULL) % 1023;
  
  b = 74          :                                 01001010
  b 
   * 0x0202020202 :       1000000010000000100000001000000010
     = 9494949494 :01001010010010100100101001001010010010100
    &amp; 10884422010 :10000100010000100010000100010000000010000 
      = 84000010  :         10000100000000000000000000010000
    % 1023        :                               1111111111
      = 82        :                                 01010010
  </code></pre>
  
  <p>Now, the only part which is somewhat unclear is the part where the big number modulo by 1023 (2^10 - 1) packs and gives me the inverted bits... I did not find any good doc about relationship between bit operations and the modulo operation (beside <code>x % 2^n == x &amp; (2^n - 1))</code>) so maybe if someone would cast a light on this it would be very fruitful.</p>