title: Java results differ for (int)Math.pow(2,x) and 1<<x
body: <p>Why do the following two operations yield different results in Java for <code>x = 31</code> or <code>32</code> but the same results for <code>x=3</code>?</p>
  
  <pre><code>int x=3;
  int b = (int) Math.pow(2,x);
  int c = 1&lt;&lt;x;
  </code></pre>
  
  <p>Results:</p>
  
  <pre><code>x=32: b=2147483647; c=1;
  x=31: b=2147483647; c=-2147483648;
  x=3:  b=8         ; c=8
  </code></pre>