title: How to find the largest power of 2 less than the given number
body: <p>I need to find the largest power of 2 less than the given number.<br>
  And I stuck and can't find any solution.</p>
  
  <p><strong>Code:</strong> </p>
  
  <pre><code>public class MathPow {
     public int largestPowerOf2 (int n) {
          int res = 2;        
          while (res &lt; n) {
              res =(int) Math.pow(res, 2);
          }
          return res;
     }
  }
  </code></pre>
  
  <p>This doesn't work correctly.  </p>
  
  <p><strong>Testing output:</strong></p>
  
  <pre><code>Arguments Actual Expected
  -------------------------
  9         16     8       
  100       256    64      
  1000      65536  512     
  64        256    32      
  </code></pre>
  
  <p>How to solve this issue?</p>