code: public static final byte highBit(int n)
      {
          if (n <= 0) {
              return -1;
          }
  
          byte bit = 0;
  
          if (n >= 1 << 16) {
              n >>= 16;
          bit += 16;
          }
  
          if (n >= 1 << 8) {
              n >>= 8;
          bit += 8;
          }
  
          if (n >= 1 << 4) {
              n >>= 4;
          bit += 4;
          }
  
          if (n >= 1 << 2) {
              n >>= 2;
          bit += 2;
          }
  
          if (n >= 1 << 1) {
              n >>= 1;
          bit += 1;
          }
  
          return bit;
      }
docs: Find the highest bit in a positive integer. This is done
  by doing a binary search through the bits.
  
  @param n is the integer
  
  @return the bit number of the highest bit, with 0 being
  the low order bit, or -1 if <code>n</code> is not positive