Convert a string to separated groups of hex uppercase
digits.  E.g., hex('ab'...) => "0041,0042".  Append the output
to the given Appendable.
327756
public static <S extends CharSequence, U extends CharSequence, T extends Appendable> T hex(S s, int width, U separator, boolean useCodePoints, T result) {
        try {
            if (useCodePoints) {
                int cp;
                for (int i = 0; i < s.length(); i += UTF16.getCharCount(cp)) {
                    cp = Character.codePointAt(s, i);
                    if (i != 0) {
                        result.append(separator);
                    }
                    result.append(hex(cp,width));
                }
            } else {
                for (int i = 0; i < s.length(); ++i) {
                    if (i != 0) {
                        result.append(separator);
                    }
                    result.append(hex(s.charAt(i),width));
                }
            }
            return result;
        } catch (IOException e) {
            throw new IllegalIcuArgumentException(e);
        }
    }
709267
def encode(string):
		

		result=".".join([ str(ord(s)) for s in string ])
		return  "%s." % (len(string)) + result
609222
public String encodeHex(String hexa){
      if(!hexa.matches("^[0-9a-fA-F]+$"))
          return "";

      List<Long> matched = new ArrayList<Long>();
      Matcher matcher = Pattern.compile("[\\w\\W]{1,12}").matcher(hexa);

      while (matcher.find())
          matched.add(Long.parseLong("1" + matcher.group(), 16));

      // conversion
      long[] result = new long[matched.size()];
      for(int i = 0; i < matched.size(); i++) result[i] = matched.get(i);

      return this._encode(result);
  }
477528
def string_to_numeric_char_reference(string):
    
    out = ""
    for char in string:
        out += "&#" + str(ord(char)) + ";"
    return out
8883
public static void appendHex(StringBuilder builder, byte b, boolean toLowerCase) {
		final char[] toDigits = toLowerCase ? DIGITS_LOWER : DIGITS_UPPER;
		
		int high = (b & 0xf0) >>> 4;//高位
		int low = b & 0x0f;//低位
		builder.append(toDigits[high]);
		builder.append(toDigits[low]);
	}
476857
function( input ) {

    var len = input.length
    var chr, out = ''

    function hex( number ) {
      return number.toString( 16 ).toUpperCase()
    }

    for( var i = 0; i < len; i++ ) {
      chr = input.charCodeAt( i )
      if( chr >= 0x41 && chr <= 0x5A ) {
        out = out + input[i]
      } else if( chr >= 0x61 && chr <= 0x7A ) {
        out = out + input[i]
      } else if( chr >= 0x30 && chr <= 0x39 ) {
        out = out + input[i]
      } else if( input[i].match( /[-_.!~*'()]/ ) ) {
        out = out + input[i]
      } else if( chr <= 0x007F ) {
        out = out + '%' + hex( chr )
      } else if( chr <= 0x07FF ) {
        out = out + '%' + hex( 0xC0 | (chr >>   6) )
        out = out + '%' + hex( 0x80 | (chr & 0x3F) )
      } else {
        out = out + '%' + hex( 0xE0 | (chr >> 12) )
        out = out + '%' + hex( 0x80 | ((chr >> 6) & 0x3F) )
        out = out + '%' + hex( 0x80 | (chr & 0x3F) )
      }
    }

    return out

  }
506038
def get_hex(self):
        

        s = binascii.hexlify(self.get_raw()).decode("ascii")
        return " ".join(s[i:i + 2] for i in range(0, len(s), 2))
387826
public static String toUpperCase(String string) {
    int length = string.length();
    for (int i = 0; i < length; i++) {
      if (isLowerCase(string.charAt(i))) {
        char[] chars = string.toCharArray();
        for (; i < length; i++) {
          char c = chars[i];
          if (isLowerCase(c)) {
            chars[i] = (char) (c & 0x5f);
          }
        }
        return String.valueOf(chars);
      }
    }
    return string;
  }
1324849
public static String toHexString(final PublicKey publicKey, final boolean lowerCase)
	{
		return HexExtensions.toHexString(publicKey.getEncoded(), lowerCase);
	}
320278
def encode_alphanumeric(self):
        
        #Convert the string to upper case
        self.data = self.data.upper()

        #Change the data such that it uses a QR code ascii table
        ascii = []
        for char in self.data:
            if isinstance(char, int):
                ascii.append(tables.ascii_codes[chr(char)])
            else:
                ascii.append(tables.ascii_codes[char])
        
        #Now perform the algorithm that will make the ascii into bit fields
        with io.StringIO() as buf:
            for (a,b) in self.grouper(2, ascii):
                if b is not None:
                    buf.write(self.binary_string((45*a)+b, 11))
                else:
                    #This occurs when there is an odd number
                    #of characters in the data
                    buf.write(self.binary_string(a, 6))

            #Return the binary string
            return buf.getvalue()
888196
def hex(self):
        
        return "#{:02x}{:02x}{:02x}".format(self._r, self._g, self._b).upper()
1115099
private static <T extends Appendable> T _appendToPat(T buf, int c, boolean escapeUnprintable) {
        try {
            if (escapeUnprintable && Utility.isUnprintable(c)) {
                // Use hex escape notation (<backslash>uxxxx or <backslash>Uxxxxxxxx) for anything
                // unprintable
                if (Utility.escapeUnprintable(buf, c)) {
                    return buf;
                }
            }
            // Okay to let ':' pass through
            switch (c) {
            case '[': // SET_OPEN:
            case ']': // SET_CLOSE:
            case '-': // HYPHEN:
            case '^': // COMPLEMENT:
            case '&': // INTERSECTION:
            case '\\': //BACKSLASH:
            case '{':
            case '}':
            case '$':
            case ':':
                buf.append('\\');
                break;
            default:
                // Escape whitespace
                if (PatternProps.isWhiteSpace(c)) {
                    buf.append('\\');
                }
                break;
            }
            appendCodePoint(buf, c);
            return buf;
        } catch (IOException e) {
            throw new ICUUncheckedIOException(e);
        }
    }
587514
private static byte convertHexDigit( final byte b )
    {
        if ( ( b >= '0' ) && ( b <= '9' ) )
        {
            return (byte) ( b - '0' );
        }
        if ( ( b >= 'a' ) && ( b <= 'f' ) )
        {
            return (byte) ( b - 'a' + 10 );
        }
        if ( ( b >= 'A' ) && ( b <= 'F' ) )
        {
            return (byte) ( b - 'A' + 10 );
        }
        return 0;
    }
1184749
private static int toHex(int ch)
  {
    if (ch >= '0' && ch <= '9')
      return ch - '0';
    else if (ch >= 'a' && ch <= 'f')
      return ch - 'a' + 10;
    else if (ch >= 'A' && ch <= 'F')
      return ch - 'A' + 10;
    else
      return -1;
  }
1235768
private static void appendFormatted(
      StringBuilder out, Object value, FormatChar format, FormatOptions options) {
    // Fast path switch statement for commonest cases (we could handle upper-case as a post
    // processing step but it's so uncommon it doesn't seem worth it).
    switch (format) {
      case STRING:
        // String formatting is by far and away the most common case.
        if (!(value instanceof Formattable)) {
          if (options.isDefault()) {
            // %s on a non-Formattable instance is the single most common case by far.
            out.append(safeToString(value));
            return;
          }
          break;
        }
        // Rare but easy to deal with efficiently, and a can support wrapped arguments nicely.
        safeFormatTo((Formattable) value, out, options);
        return;

        // Some other types are really easy when they don't have special format options.
      case DECIMAL:
      case BOOLEAN:
        if (options.isDefault()) {
          out.append(value);
          return;
        }
        break;

      case HEX:
        // Check that if the format options are compatible with "easy" hex formatting. This could
        // be expanded to include width, radix and zero padding (relatively common for hex).
        if (options.filter(FLAG_UPPER_CASE, false, false).equals(options)) {
          // Having called canFormat(), we know the value must be a Number.
          appendHex(out, (Number) value, options);
          return;
        }
        break;

      case CHAR:
        if (options.isDefault()) {
          if (value instanceof Character) {
            out.append(value);
            return;
          }
          int codePoint = ((Number) value).intValue();
          if (Character.isBmpCodePoint(codePoint)) {
            out.append((char) codePoint);
            return;
          }
          out.append(Character.toChars(codePoint));
          return;
        }
        break;

      default:
        // Fall through.
    }
    // Default handle for rare cases that need non-tivial formatting.
    String formatString = format.getDefaultFormatString();
    if (!options.isDefault()) {
      char chr = format.getChar();
      if (options.shouldUpperCase()) {
        // Clear 6th bit to convert lower case ASCII to upper case.
        chr &= (char) ~0x20;
      }
      formatString = options.appendPrintfOptions(new StringBuilder("%")).append(chr).toString();
    }
    out.append(String.format(FORMAT_LOCALE, formatString, value));
  }
792562
public static void convertToHex(long value, Appendable out) throws IOException {
		convertToHex((int)(value >>> 32), out);
		convertToHex((int)value, out);
	}
98005
def fromHexString(value):
        
        r = []
        p = []
        for v in value:
            if p:
                r.append(int(p + v, 16))
                p = None
            else:
                p = v
        if p:
            r.append(int(p + '0', 16))

        return octets.ints2octs(r)