區位碼是用4個十進制數字,來代表一個中文字。
而區位碼的前兩位稱之為區碼,稱制之為位碼。
完整程式碼範例如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
public class Word2BlockCode { public static void main(String[] args) { out.println(toBlockCode("我")); } private static String toBlockCode(String textString) { if(textString.length() > 2) { return "Please do not put so many word."; } byte[] codeBit = textString.getBytes(); if(codeBit.length < 2) { return "Please put Chinse word in this function."; } codeBit[0] -= 160; codeBit[1] -= 160; String codeString = formateNumber(codeBit[0]) + formateNumber(codeBit[1]); return codeString; } private static String formateNumber(int num) { String formateString = String.format("%02d", num); return formateString; } } |
完整專案(連結)
文章標籤
全站熱搜
