- import java.io.UnsupportedEncodingException;
- public class TQC209 {
- /**
- * @param args
- */
- public static void main(String[] args) throws UnsupportedEncodingException
- {
- String str="JAVA程式";
- String u2hex=toHex(str);
- System.out.print("Unicode 碼16進位\t");
- System.out.println(u2hex);
- String toBig5=new String(str.getBytes("Big5"),"ISO8859_1");
- String b2hex=toHex(toBig5);
- System.out.print("Big5 碼16進位\t\t");
- System.out.println(b2hex);
- System.out.print("原字串\t\t\t\t");
- System.out.println(str);
- }
- private static String toHex(String str) {
- // TODO Auto-generated method stub
- String res="";
- char tmp;
- for(int i=0;i<str.length();i++)
- {
- tmp=str.charAt(i);
- String t="00000"+Integer.toHexString(tmp);
- res +=t.substring(t.length()-4)+" ";
- }
- return res;
- }
- }
複製代碼 |