62,621
社区成员
发帖
与我相关
我的任务
分享
String s = "秋";
byte[] b = s.getBytes("gbk");
for(int i=0; i<b.length; i++)
{
System.out.println(b[i]);
}
public class TestGBK {
public static void main(String args[]){
String s = "秋";
try{
byte[] b = s.getBytes("gbk");
for(int i=0; i<b.length; i++)
System.out.println(b[i] & 0XFF);
}catch(Exception e){
e.printStackTrace();
}
}
}
String s = "秋";
byte[] b = s.getBytes("gbk");
for (int i = 0; i < b.length; i++) {
System.out.println(Integer.toHexString(b[i]&0xFF));
System.out.println(Integer.toBinaryString(b[i]&0xFF));
}
输出:
c7
11000111 //-57的二进制补码
ef
11101111
public class TestGBK {
public static void main(String args[]){
String s = "秋";
try{
byte[] b = s.getBytes("gbk");
for(int i=0; i<b.length; i++)
{
System.out.println((int)b[i]);
}
}catch(Exception e){
e.printStackTrace();
}
}
}