code: private static int bitsToEncode(int value) {
          int highestOneBit = Integer.highestOneBit(value);
          int bitLength = 0;
          while ((highestOneBit >>= 1) != 0) {
              bitLength++;
          }
  
          return bitLength;
      }
docs: Calculates the minimum number of bits required to encode a value.  This can
  then in turn be used to calculate the number of septets or octets (as
  appropriate) to use to encode a length parameter.
  
  @param value The value to calculate the minimum number of bits required to encode
  @return The minimum number of bits required to encode the supplied value