title: Why does the right-shift operator produce a zero instead of a one?
body: <p>i am teaching myself java and i work through the exercises in Thinking in Java.</p>
  
  <p>On page 116, exercise 11, you should right-shift an integer through all its binary positions and display each position with Integer.toBinaryString.</p>
  
  <pre><code>public static void main(String[] args) {
  int i = 8;
  System.out.println(Integer.toBinaryString(i));
  int maxIterations = Integer.toBinaryString(i).length();
  int j;
  for (j = 1; j &lt; maxIterations; j++) {
      i &gt;&gt;= 1;
  System.out.println(Integer.toBinaryString(i));
  }
  </code></pre>
  
  <p>In the solution guide the output looks like this:</p>
  
  <pre><code>1000
  1100
  1110
  1111
  </code></pre>
  
  <p>When i run this code i get this:</p>
  
  <pre><code>1000
  100
  10
  1
  </code></pre>
  
  <p>What is going on here. Are the digits cut off?</p>
  
  <p>I am using jdk1.6.0_20 64bit. The book uses jdk1.5 32bit.</p>