title: Understanding logic behind Integer.highestOneBit() method implementation
body: <p>Java Integer class has the static method highestOneBit method which will return a value with a single one-bit, in the position of the highest-order one-bit in the specified value, or zero if the specified value is itself equal to zero.</p>
  
  <p>For example input of int 17 will return 16; As 17 can be represented in binary as 10001 so it will return the furthest bit left which is equal to 16. </p>
  
  <p>And in Integer class it has the following implementation in Java doc.</p>
  
  <pre><code>    public static int highestOneBit(int i) {
      // HD, Figure 3-1
      i |= (i &gt;&gt;  1);
      i |= (i &gt;&gt;  2);
      i |= (i &gt;&gt;  4);
      i |= (i &gt;&gt;  8);
      i |= (i &gt;&gt; 16);
      return i - (i &gt;&gt;&gt; 1);
  }
  </code></pre>
  
  <p>I just want to know the logic behind implementing it this way and the logic behind using shift operations
  . Can any one put some light on it. </p>