code: static void appendHex(StringBuilder out, Number number, FormatOptions options) {
      // We know there are no unexpected formatting flags (currently only upper casing is supported).
      boolean isUpper = options.shouldUpperCase();
      // We cannot just call Long.toHexString() as that would get negative values wrong.
      long n = number.longValue();
      // Roughly in order of expected usage.
      if (number instanceof Long) {
        appendHex(out, n, isUpper);
      } else if (number instanceof Integer) {
        appendHex(out, n & 0xFFFFFFFFL, isUpper);
      } else if (number instanceof Byte) {
        appendHex(out, n & 0xFFL, isUpper);
      } else if (number instanceof Short) {
        appendHex(out, n & 0xFFFFL, isUpper);
      } else if (number instanceof BigInteger) {
        String hex = ((BigInteger) number).toString(16);
        out.append(isUpper ? hex.toUpperCase(FORMAT_LOCALE) : hex);
      } else {
        // This will be caught and handled by the logger, but it should never happen.
        throw new RuntimeException("unsupported number type: " + number.getClass());
      }
    }
docs: Visible for testing