code: private static int getClosestPowerOf2(int value) {
      if (value <= 0)
        throw new IllegalArgumentException("Undefined for " + value);
      final int hob = Integer.highestOneBit(value);
      return Integer.numberOfTrailingZeros(hob) +
        (((hob >>> 1) & value) == 0 ? 0 : 1);
    }
docs: Return the exponent of the power of two closest to the given
  positive value, or zero if value leq 0.
  This follows the observation that the msb of a given value is
  also the closest power of two, unless the bit following it is
  set.