title: Finding Highest Order 1 in a Java Primitive
body: <p>I need to find the highest order 1 in some longs, ints, and shorts in Java. For example, if I had a char that looked like <code>00110101</code>, I need a method that will return 2 (index of highest order 1).</p>
  
  <p>Now, I know that you can do this using a for loop like:</p>
  
  <pre><code>for(int i=0; i&lt;8; i++)
      if((x &amp; 1&lt;&lt;i) != 0) return i;
  return -1;
  </code></pre>
  
  <p>but this is way slower than what I want to do. I know modern CPUs have instructions that do this on chip, so I want to know how I can make a call to that rather than having an explicit loop.</p>
  
  <p>EDIT: Bonus points if you can just return the indices of all of the ones in the primitive.</p>
  
  <p>Thanks.</p>