Код: Выделить всё
public static void main(String[] args)
throws UnsupportedEncodingException, CharacterCodingException {
String st = "ñ";
for (int i = 0; i < st.length(); i++) {
int unicode = st.charAt(i);
codepointToUTF8(unicode);
}
}
public static byte[] codepointToUTF8(int codepoint) {
byte[] hb = codepointToHexa(codepoint);
byte[] binaryUtf8 = null;
if (codepoint = 0) {
// we fill it and advance the iterator
binarybyte[i] = hbbinary[hbindex];
hbindex--;
filled[i] = true;
} else if (!filled[i]) {
binarybyte[i] = 0;
filled[i] = true;
}
}
return binarybyte;
}
private static byte[] convertHexaArrayToBinaryArray(byte[] hb) {
byte[] binaryArray = new byte[hb.length * 4];
String aux = "";
for (int i = 0; i < hb.length; i++) {
aux = Integer.toBinaryString(hb[i]);
int length = aux.length();
// toBinaryString doesn't return a 4 bit string, so we fill it with 0s
// if length is not a multiple of 4
while (length % 4 != 0) {
length++;
aux = "0" + aux;
}
for (int j = 0; j < aux.length(); j++) {
binaryArray[i * 4 + j] = (byte) (aux.charAt(j) - '0');
}
}
return binaryArray;
}
Подробнее здесь: https://stackoverflow.com/questions/383 ... operations