Here you can find the source of charToUnicodeSequence(final StringBuilder buf, final char ch)
public static void charToUnicodeSequence(final StringBuilder buf, final char ch)
//package com.java2s; //License from project: Apache License public class Main { private static final char[] HEX_DIGIT = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; private static final int MAX_HEX_DIGIT = 0xF; public static void charToUnicodeSequence(final StringBuilder buf, final char ch) { buf.append("\\u"); buf.append(toHex((ch >> 12) & MAX_HEX_DIGIT)); buf.append(toHex((ch >> 8) & MAX_HEX_DIGIT)); buf.append(toHex((ch >> 4) & MAX_HEX_DIGIT)); buf.append(toHex(ch & MAX_HEX_DIGIT)); }//from www . j ava 2s. c o m public static char toHex(final int nibble) { return HEX_DIGIT[(nibble & MAX_HEX_DIGIT)]; } /** * @param data Data to encode. * @param separator How to separate the bytes in the output * @return The byte array encoded as a string of hex digits separated by given separator. */ public static String toHex(final byte[] data, final String separator) { if (data.length == 0) { return ""; } final StringBuilder sb = new StringBuilder(data.length * (separator.length() + 2) - separator.length()); for (int i = 0; i < data.length; i++) { if (i > 0) { sb.append(separator); } sb.append(toHex((data[i] & 0xF0) >> 4)); sb.append(toHex(data[i] & 0x0F)); } return sb.toString(); } }