Пример #1
0
  /**
   * Converts a long value to a hexadecimal String of length 16. Includes leading zeros if
   * necessary.
   *
   * @param value The long value to be converted.
   * @return The hexadecimal string representation of the long value.
   */
  public static String toFullHexString(long value) {
    long currentValue = value;
    StringBuffer stringBuffer = new StringBuffer(16);
    for (int j = 0; j < 16; j++) {
      int currentDigit = (int) currentValue & 0xf;
      stringBuffer.append(HEX_DIGITS[currentDigit]);
      currentValue >>>= 4;
    }

    return stringBuffer.reverse().toString();
  }
Пример #2
0
  /**
   * Converts a int value to a hexadecimal String of length 8. Includes leading zeros if necessary.
   *
   * @param value The int value to be converted.
   * @return The hexadecimal string representation of the int value.
   */
  public static String toFullHexString(int value) {
    int currentValue = value;
    StringBuffer stringBuffer = new StringBuffer(8);
    for (int i = 0; i < 8; i++) {
      int currentDigit = currentValue & 0xf;
      stringBuffer.append(HEX_DIGITS[currentDigit]);
      currentValue >>>= 4;
    }

    return stringBuffer.reverse().toString();
  }
Пример #3
0
  /**
   * Converts a byte array to a hexadecimal String. Each byte is presented by its two digit
   * hex-code; 0x0A -> "0a", 0x00 -> "00". No leading "0x" is included in the result.
   *
   * @param value the byte array to be converted
   * @return the hexadecimal string representation of the byte array
   */
  public static String toHexString(byte[] value) {
    if (value == null) {
      return null;
    }

    StringBuffer buffer = new StringBuffer(2 * value.length);
    int single;

    for (int i = 0; i < value.length; i++) {
      single = value[i] & 0xFF;

      if (single < 0x10) {
        buffer.append('0');
      }

      buffer.append(Integer.toString(single, 16));
    }

    return buffer.toString();
  }