public class 中文字符转GBK码{
public static void main(String[] args) throws Exception {
String s=new String("座".getBytes(),"unicode");
StringBuilder sb=new StringBuilder();
for(Character c:s.toCharArray()){
sb.append(Integer.toBinaryString(c));
}
System.out.println(String.format("%4x", Long.parseLong(sb.toString(), 2)));
}
}
public static void main(String[] args) throws Exception {
String s=new String("座".getBytes(),"unicode");
StringBuilder sb=new StringBuilder();
for(Character c:s.toCharArray()){
sb.append(Integer.toBinaryString(c));
}
System.out.println(String.format("%4x", Long.parseLong(sb.toString(), 2)));
}
}
本文提供了一个Java示例程序,演示如何将中文字符转换为GBK编码格式。通过使用Unicode编码作为中间步骤,该程序将字符转换为二进制形式,并最终输出其对应的GBK编码。
5058

被折叠的 条评论
为什么被折叠?



