Exemplo n.º 1
0
 /**
  * Convert an integer to an Hexa string and pad the result with '0'
  *
  * @param value the int to convert
  * @param nChars the number of characters of the result
  * @return the resulting string
  * @ibm-api
  * @throws NumberFormatException if nChars is less that the actual number of characters needed
  */
 public static final String toUnsignedHex(int value, int nChars) {
   FastStringBuffer b = new FastStringBuffer();
   // String s = Integer.toHexString(value);
   for (int i = 7; i >= 0; i--) {
     int v = (value >>> (i * 4)) & 0x0F;
     if (b.length() > 0 || v != 0 || i < nChars || i == 0) {
       b.append(hexChar(v));
     }
   }
   if (nChars > 0 && b.length() > nChars) {
     throw new NumberFormatException(
         StringUtil.format(
             "Hexadecimal number {0} too big to fit in '{1}' characters", // $NLS-StringUtil.StringUtil.HexNumTooBig.Exception-1$
             StringUtil.toString(value), StringUtil.toString(nChars)));
   }
   return b.toString();
 }