java 代码
- public void printUtfBinary(String str)
- {
- try
- {
- byte[] c = str.getBytes("UTF-8");
- System.out.println("UTF-8:");
- for(int i = 0; i < c.length; ++i)
- {
- String bin = Integer.toBinaryString(c[i]);
- bin = bin.substring(str.length() - 8);
- System.out.println(" " + bin);
- }
- }
- catch(Exception e)
- {
- e.printStackTrace();
- }
- }