title: square root by bit shift
body: <p>I am studying the fast square root algorithm by bit shift. I was stuck by the code from wikipedia. </p>
  
  <pre><code>short isqrt(short num) {
      short res = 0;
      short bit = 1 &lt;&lt; 14; // The second-to-top bit is set: 1L&lt;&lt;30 for long
  
      // "bit" starts at the highest power of four &lt;= the argument.
      while (bit &gt; num)
          bit &gt;&gt;= 2;
  
      while (bit != 0) {
          if (num &gt;= res + bit) {
              num -= res + bit;
              res = (res &gt;&gt; 1) + bit;
          }
          else
              res &gt;&gt;= 1;
          bit &gt;&gt;= 2;
      }
      return res;
  }
  </code></pre>
  
  <p>I know it can generate the correct result, but how does it make it? I am especially confused by this sentence, 
  res = (res >> 1) + bit;
  Why res should be divided by 2 here?
  Can anyone shed some light on this? Thank!</p>