1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| public static int windows1252Of(char ch) {
try {
String s = new String(new char[] {ch});
byte[] sBytes = s.getBytes("windows-1252");
// windows-1252 encode tous ses caractères sur 1 octet,
// et nous savons que notre String fait 1 caractère.
// Donc le tableau fait 1 octet, et nous prenons cet octet.
int code = sBytes[0] & 0xFF; // 0xFF parce qu'un byte va de -128 à 127, et qu'on veut le int de 0 à 255.
return code;
} catch(UnsupportedEncodingException e) {
throw new IllegalStateException(e.getMessage(), e);
}
}
public static void main(String[] args) {
int localCode = windows1252Of('');
System.out.println(localCode);
} |